473,395 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

calculate number of days since Jan 1, 0000

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.

...thanks for looking..
--
================================================== ====================
Joseph "Beemer Biker" Stateson
http://TipsForTheComputingImpaired.com
http://ResearchRiders.org Ask about my 99'R1100RT
================================================== ====================
Jun 26 '07 #1
5 13604
There is no year zero, is there? I believe it goes 3 BC, 2 BC, 1 BC, 1 AD, 2
AD, ...

"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.

...thanks for looking..
--
================================================== ====================
Joseph "Beemer Biker" Stateson
http://TipsForTheComputingImpaired.com
http://ResearchRiders.org Ask about my 99'R1100RT
================================================== ====================
Jun 26 '07 #2
"ModelBuilder" <Mo**********@discussions.microsoft.comwrote in message
news:50**********************************@microsof t.com...
There is no year zero, is there? I believe it goes 3 BC, 2 BC, 1 BC, 1
AD, 2
AD, ...
Correct.

Also, just as an aside, "old" dates can be a bit tricky if the solution is
trying to store them in SQL Server:
http://weblogs.sqlteam.com/mladenp/a.../16/52754.aspx
--
http://www.markrae.net

Jun 26 '07 #3
PS
"Beemer Biker" <js*******@swri.eduwrote in message
news:13*************@corp.supernews.com...
>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.
Just factor in the extra days that you need when you use DateTime.MinValue
in your method. Why don't you give us a specific date and the number that
you want to see as representing that date?

PS
>
..thanks for looking..
--
================================================== ====================
Joseph "Beemer Biker" Stateson
http://TipsForTheComputingImpaired.com
http://ResearchRiders.org Ask about my 99'R1100RT
================================================== ====================


Jun 26 '07 #4
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.

You might also want to be very careful about calendars - we've skipped
days in the past when calendars used were changed.

Alun Harford
Jun 26 '07 #5
"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
Jun 26 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: JP SIngh | last post by:
Hi All I need to calculate the number of working days between the two dates entered on an ASP page. I am not that great a coder in ASP and was wondering if someone can help. Basically the...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
11
by: Laery | last post by:
Hi, I'm currently adding a new module to an old borland C3.1 application (dos). And I need to calculate a date by subtracting the number of days from a given date. I know I could use an...
2
by: Rustan | last post by:
Hi Im using GregorianCalendar to find out the current years week numbers. When the user chooses a week number in a dropdown i want to show that week in a table with the corresponding dates. For...
29
by: james | last post by:
I have a problem that at first glance seems not that hard to figure out. But, so far, the answer has escaped me. I have an old database file that has the date(s) stored in it as number of days. An...
7
by: Sam | last post by:
Hi, I use C# in my ASP.NET projects. Here's what I need to do: I want to add x business days to a given date i.e. add 12 business days to today's date. What is the best, fastest and most...
3
by: Libber39 | last post by:
Hi everyone, Have a query on how to calculate the amount of weeks and days contained in a number in an access query. ie: the difference in days between 2 dates amounts to 17 days. I want to now...
4
by: shilpareddy2787 | last post by:
Hello, I have some total values, I want to calculate percenatge of these Total Values. I want to divide the total with No. Of working Days Excluding Saturdays and Sundays in a given period. ...
15
by: student4lifer | last post by:
Hello, I have 2 time fields dynamically generated in format "m/d/y H:m". Could someone show me a good function to calculate the time interval difference in minutes? I played with strtotime() but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.