"Alun Harford" <de*****@alunharford.co.ukwrote in message

news:eA**************@TK2MSFTNGP04.phx.gbl...

Beemer Biker wrote:
>I cant seem to get that date into any DateTime to make my calculation

directly by subtracting "01-01-0000" from "now".

After reading this:

http://www.mathworks.com/matlabcentr...bjectType=File I

kluged up this routine that works:

// convert date time into that funny matlab serial date time that starts

at jan 1, 0000

private string DT2Matlab(DateTime thisDT)

{

DateTime y1970 = Convert.ToDateTime("JAN-1-1970");

thisDT = thisDT.AddDays(719529);

// supposidly 719529 days from "0 CE" to 1970

TimeSpan ts = thisDT.Subtract(y1970);

return ts.TotalDays.ToString("#.####");

}

Seems there should be a cleaner way to calculate "Days.fraction_of_days"

from "0 CE" all in one swoop? "01-01-0001" gives the wrong answer when

subtracting and the 0000 is a no go.

As has been said, there is no year 0, just as there is no month 0.

Thanks Alun! I read where the year "0" is just a reference point, as

explained here:

http://tinyurl.com/39b9es
quoteing "datenum is one of three conversion functions that enable you to

express dates and times in any of three formats in MATLAB: a string (or date

string), a vector of date and time components (or date vector), or as a

numeric offset from a known date in time (or serial date number). Here is an

example of a date and time expressed in the three MATLAB formats:

Date String: '24-Oct-2003 12:45:07'

Date Vector: [2003 10 24 12 45 07]

Serial Date Number: 7.3188e+005

A serial date number represents the whole and fractional number of days from

a specific date and time, where datenum('Jan-1-0000 00:00:00') returns the

number 1. (The year 0000 is merely a reference point and is not intended to

be interpreted as a real year in time.)"

I was looking for a clean (??) C# function to calculate that 7.3188e+005

Googleing I found a UTC -Matlab that used 1970. I thought there might be

a clean way to get the time span in days.fraction_of_days out of the

DateTime function. What I have works, though it is probably not accurate

by "days in the past" let alone leap-seconds. I have a C# program that

generates a text file that is being used as input to a matlab program. The

engineer wants time in that funny number that matlab uses and was not happy

when I put out a date time string accurate down into milliseconds.

You might also want to be very careful about calendars - we've skipped

days in the past when calendars used were changed.

Alun Harford