Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to convert Gregorian date to Julian. 1

Status
Not open for further replies.

new777

Technical User
Mar 1, 2007
10
US
Greetings,

I'm trying to convert dates stored in grerogian calendar to julian calendar; in other words I need 20080101 to become 108001. Did not see anything in VFP help besides julian day calculation, which is not exaclty what I need. Any advise is highly appreciated. Thank you in advance.
 

VFP has

SYS(1) - Julian System Date,
SYS(10) - String from Julian Day Number,
SYS(11) - Julian Day Number,

and plenty of other functions to manipulate those dates.

You say, it's not exactly what you need? Then, perhaps, I don't understand what is it that you need (and how did you arrive from 20080101 to 108001). Can you clarify, please?
 
VFP provides Julian day functions, but I'm looking for something that would manipulate Julian dates. 108001 is a Julian date for 20080101. Hope that makes sense.
 
108001 is a Julian date for 20080101. Hope that makes sense.

It doesn't. Please explain how you arrived at 108001. It certainly doesn't resemble a Julian date in the accepted sense of the term.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 

Mike,
I think I guessed it.

108 is a year number since 1900,
001 is a day number within a year.

I have seen someone using this or a similar construct calling it a Julian date. Possibly, here: thread183-1420590.

new777,
If that's what you mean, you can write your own function to create that.
 
108001 brakes down as following: 1 is for century, 08 is for the year and 001 is for the day of the year. Well, I guess this is not real Julian date, but often reffered as one. This site has some explanations:
 

You link says the following:
The converter at right will convert any date entered to the Ordinal date, sometimes referred incorrectly as the "Julian date format".

So then PADL(theYear-1900, 3, "0") will get you the first 3 positions,
PADL(DATE(theYear, 1, 1)-DATE(theYear, theMonth, theDate)+1, 3, "0") will get the second 3 positions, then concatenate them - that's if you need to get a string.

Or, for a number,

(theYear-1900)*1000+(DATE(theYear, 1, 1)-DATE(theYear, theMonth, theDate)+1)

theYear, theMonth, theDate here are for the date you need to convert.
 
Hmmm,
SYS(11,DATE(2008,1,1)) -> 2454467
how did you get 108001?

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Thank you, Stella! Simple and ingenious solution and I was afraid that I'll end up writing complicated routine. This statement gives the desired date: PADL(YEAR(DATE())-1900, 3, "0")+PADL(DATE(YEAR(DATE()), MONTH(DATE()), DAY(DATE()))-DATE(YEAR(DATE()),1,1),3,"0")
 
Borislav,

I, probably, was not clear. I actually supported what you said. That's what I meant - that not only your converter at returns 2454467, but VFP's own SYS(11).

As for 108001, I figured it out in my post dated 11-Dec-08 14:40.


new777,

You construct DATE(YEAR(DATE()), MONTH(DATE()), DAY(DATE())) is redundant. I thought you will be extracting your values from a string like 20080101. If you use DATE() as an input date, you don't need to extract year, month and day from it, then put it back together. Just use DATE() as it is.

PADL(YEAR(DATE())-1900, 3, "0")+PADL(DATE()-DATE(YEAR(DATE()),1,1)+1, 3, "0")

Or, even better, you can use a date type variable:

PADL(YEAR(dMyDate)-1900, 3, "0")+PADL(dMyDate-DATE(YEAR(dMyDate), 1, 1)+1, 3, "0")

Notice that I added 1 to the result of date subtraction - otherwise, you will start counting days of the year from 0 not 1.


Good luck and thanks for the star.
 
New 777,

to convert a given gregorgiandate you could make following function:

function julian
PARAMETERS tcgeorgiandate
lcJulian = SYS(11,tcgeorgiandate)
? lcJulian


and call the function with any greorgiandate, e.g. date()-150

the result will be the julian number for date()-150

Is this what you are looking for??

Regards,

Jockey2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top