Board index » cppbuilder » JulianDateToDateTime

JulianDateToDateTime


2006-01-04 08:21:32 PM
cppbuilder54
Hello everybody!!
I'm trying to use "JulianDateToDateTime" function because I've a file with a
date encoded as YEAR (int) and JulianDAY (another int).
For example I've 2005 and 65
Now, I'm trying to decode this "65" in month and day inteeger numbers.
Can you help me?
Thanks!!
Andrea
 
 

Re:JulianDateToDateTime

"Bono" < XXXX@XXXXX.COM >wrote:
Quote
I'm trying to use "JulianDateToDateTime" function because I've a file with a
date encoded as YEAR (int) and JulianDAY (another int).
For example I've 2005 and 65

Now, I'm trying to decode this "65" in month and day inteeger numbers.
Can you help me?
Strictly speaking, that's not a Julian Day. (A Julian Day is the number
of days since a particular epoch point - originally Monday 1st January,
4713 BC.) On the other hand, it _is_ the Julian day as used by many
computer programs.
However, the usage that you indicate is the day-of-year. It's trivially
easy to convert to month and day-of-month, as long as you know how many
days there are in each month.
Don't forget:
isLeapYear = ((year % 400) == 0)
|| (((year % 4) == 0) && ((year % 100) != 0));
otherwise, you'll be running into the Y2K bug.
A simple pair of lookup tables containing the first day of the month for
leap and normal years is probably the easiest way to go.
You might also like to check the struct tm definition, which has a
tm_yday field that is zero-based.
Alan Bellingham
--
ACCU Conference 2006 - 19-22 April, Randolph Hotel, Oxford, UK
 

Re:JulianDateToDateTime

// Parameters : Year, Month, Date as WORD's
//
// Return : Number of elapsed days from 0AD to given date.
// If date is illegal returns -1
//
long GetElapsed(WORD Year, WORD Month, WORD Date)
{
double a, b, Jdt;
WORD YY, MM;
if ( ( ( (Year%4 != 0) ||
( (Year%4 == 0) && (Year%100 == 0) && (Year%400 != 0) ) ) &&
( (Month==2) && (Date>28) ) ) ||
(Year == 0) || (Month == 0) || (Date == 0) || (Month>12) ||
(Date>31) ||
(((Month == 4) || (Month == 6) || (Month == 11)) && (Date>30) ||
((Month == 2) && (Date>29)) ||
((Year == 1752) && (Month == 9) && (Date>= 3 && Date <= 13))) ||
(Year < 1600) || (Year>2100) )
{
return -1;
}
else
{
if (Month>2)
{
YY = Year;
MM = Month;
}
else
{
YY = WORD(Year-1);
MM = WORD(Month+12);
}
a = floor(YY/100);
b = 2-a+floor(a/4);
Jdt=365.25*YY;
Jdt=floor( Jdt )+floor( 30.6001*( MM+1 ) )+Date+3+b;
Jdt=ceil(Jdt-0.5);
if ( (Year<=1752) && ((Month<9) || ((Month==9) && (Date<14))) )
Jdt -= 10;
return (long(ceil(Jdt)));
}
}
This an old, old function that I originally found in an Amstrad CPC
magazine. It's been ported from BASIC to Pascal to C.
NMote that it deals with the British 1752 date issue. If you intend to
use dates prior to the 20th century you might have to adjust this
function if you don't live in Britain or one of its old colonies :)
--
Andrue Cope [TeamB]
[Bicester, Uk]
info.borland.com/newsgroups/guide.html
 

{smallsort}