Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Storing a date into its simplest format
Message
From
31/01/2008 07:35:46
John Baird
Coatesville, Pennsylvania, United States
 
 
To
30/01/2008 18:19:03
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01287307
Message ID:
01287419
Views:
14
>>How about a julian date?
>
>Could you elaborate more on the topic?

Ajulian date is a numerical representation of a date from a date in jewish history. Today's date would be something like 2, 356, 154. So if you take the julian date and subtract a number, say 2,000,000, you have an integer representation of the date. Easy to store and retrieve.

Here's the routines for the calculation:
public static long ConvertToJulian( DateTime dt)
{
  	int m = dt.Month;
  	d = dt.Day;
  	int y = dt.Year;

	if(m < 3)
        {
   		m = m + 12;
      		y=y-1 ;
	}
	
        long jd = d + (153 * m - 457) / 5 + 365 * y + (y / 4) - (y / 100) + (y / 400) + 1721119;

        return jd;
}


public static DateTime ConvertFromJulian(int julianDate)
{
	long l = julianDate + 68569;
        long n = (long) ((4*l)/146097) ;
        l = l - ((long)((146097 * n + 3)/4) );
        long i = (long) ((4000 *(l + 1)/1461001)) ;
        l = l - (long)((1461*i)/4) + 31; 
        long j = (long)((80*l)/2447); 
        int Day = (int)(l - (long)((2447*j)/80));
        l=(long)(j/11) ;
        int Month = (int)(j + 2 - 12*l);
        int Year = (int)(100*(n-49) + i + l) ;

        DateTime dt = new DateTime(Year,Month,Day);

        return dt;
}
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform