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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert date like this: 2453748 to 2005-Jan-14

Status
Not open for further replies.

djbeta

IS-IT--Management
Apr 16, 2004
46
US

Please forgive my newbidity, I've tried to search the php forums and manual but I'm not even sure what sort of date I'm dealing with.

I have a MySQL database with a date field (startDate) that has data in it of this form:

2453748

My first question is, what format is that ?

My second question is, how can my php script put it into a form that looks like this: 2005-Jan-06

Many thanks,
beta
 
Have you tried the [blue]date()[/blue] function.

Supposing it is a Unix Timestamp, it will convert it to a readable format. here is the link:


Hope this helps.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
the date looks like a unix timestamp. it corresponds to a date in 1970 by the looks of it.

to convert a timestamp to humanreadable form:
Code:
date ("Y-M-d",$timestamp);
 


Ug... the above code is returning 1970-Jan-29 for all the records.. and I know they're all different dates.

I checked the MySQL table, and it's an Int(7) field.


I'm basically trying to write a little interface that will allow a user to quickly edit records in an existing php mySQL application: Easy PHP Calendar.

Could this mean that the author of the application is using his own calculation to render dates into and from a 7 digit integer ? (possibly for some sort of copy protection)


 

Yes, i have verified that..

I just found on the developer's forum that he uses Julian Date format

is Gregorian the format I want to be in for the above code to work ?

I see there is a jdtogregorian function

to use it it says jdtogregorian(int date)
what is the "int" in there.. do i just leave the
letters "int" in there ??

am i going about this correctly ???

should I declare a variable to change the date to the right format ?

 
If you run the integer you posted through jdtojulian() you will get the date in this format: '12/30/2005'.

If you then run a date through: juliantojd() you will get the Julian Day Count (the integer you posted)

Examples:
Code:
<?php
//this line prints '2453748' to the screen
echo juliantojd(12, 30, 2005);

//this line prints '12/30/2005' to the screen
echo jdtojulian(2453748);
?>

After retrieving the date through jdtojulian(), you can now format it any way you like using the date() function, along with explode(), or any other number of options.
 
One thing I forgot to mention, (and you probably already realized) when a user submits a new date you will need to covert that to mm, dd, yy. Then send that through juliantojd() to get an integer before inserting/updating the db. This way the rest of the application will know what to do with the data.
 
don't you need to make the field bigger? the current number of seconds since 1/1/1970 has at 10 figures so an int(7) is not going to contain the date properly.

i can't think of a date format (other than "yymmdd" a non-y2k compliant form of year) that takes only 7 figures.
 
jpadie:
The date is in stored in the Julian Date format.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top