473,782 Members | 2,498 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(DateT ime thisDT)
{
DateTime y1970 = Convert.ToDateT ime("JAN-1-1970");
thisDT = thisDT.AddDays( 719529);
// supposidly 719529 days from "0 CE" to 1970
TimeSpan ts = thisDT.Subtract (y1970);
return ts.TotalDays.To String("#.####" );
}

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 13671
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(DateT ime thisDT)
{
DateTime y1970 = Convert.ToDateT ime("JAN-1-1970");
thisDT = thisDT.AddDays( 719529);
// supposidly 719529 days from "0 CE" to 1970
TimeSpan ts = thisDT.Subtract (y1970);
return ts.TotalDays.To String("#.####" );
}

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
"ModelBuild er" <Mo**********@d iscussions.micr osoft.comwrote in message
news:50******** *************** ***********@mic rosoft.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.supe rnews.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(DateT ime thisDT)
{
DateTime y1970 = Convert.ToDateT ime("JAN-1-1970");
thisDT = thisDT.AddDays( 719529);
// supposidly 719529 days from "0 CE" to 1970
TimeSpan ts = thisDT.Subtract (y1970);
return ts.TotalDays.To String("#.####" );
}

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.MinVal ue
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(DateT ime thisDT)
{
DateTime y1970 = Convert.ToDateT ime("JAN-1-1970");
thisDT = thisDT.AddDays( 719529);
// supposidly 719529 days from "0 CE" to 1970
TimeSpan ts = thisDT.Subtract (y1970);
return ts.TotalDays.To String("#.####" );
}

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*****@alunha rford.co.ukwrot e in message
news:eA******** ******@TK2MSFTN GP04.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(DateT ime thisDT)
{
DateTime y1970 = Convert.ToDateT ime("JAN-1-1970");
thisDT = thisDT.AddDays( 719529);
// supposidly 719529 days from "0 CE" to 1970
TimeSpan ts = thisDT.Subtract (y1970);
return ts.TotalDays.To String("#.####" );
}

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_o f_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
4748
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 form has Two textboxes to enter dates From Date - Fdate To Date - TDate
53
5746
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 difficult to know what is going on. One of these Order Forms you can see here... http://www.cardman.co.uk/orderform.php3
11
6477
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 array of days in the months and go back by leaping when 1 is reached. (keeping the 29the of feb and january/year in mind).
2
34351
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 example : the user choses week43 (this week) so somehow i must calculate what date is startdate that week (monday 18th). How do i do this with c# ? all i know is that its-
29
9134
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 example is: 36,525 represents 01/01/1900. The starting point date is considered to be : 00/00/0000. I have looked thru Help and used Google and have not really found an answer. I know that Leap Years need to be accounted for too. Any...
7
25996
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 efficient way for me to do this? -- Thanks, Sam
3
5963
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 calculate in the query the amount of weeks and days within the 17 days to show 2 weeks 3 days. I can create the function within excel, (A1 as cell with the days within it) as: =INT(A1/7) & " Weeks, " & MOD(A1,7) & " days" but cant seem to...
4
11208
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. How to calculate the Total Number of working Days in a given period . Let us say If i give the period as 08/01/2008 to 08/15/2008, I want total number of working days as 11. Please help me
15
6440
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 but that only gave me difference in hours and only if the times were on the same day (after wrapping with date() function). TIA
0
9641
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10146
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9944
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.