HighDots Forums  

mySQL Timestamp in php

Macromedia Dreamweaver Macromedia Dreamweaver Discussions (macromedia.dreamweaver)


Discuss mySQL Timestamp in php in the Macromedia Dreamweaver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Brad Lawryk
 
Posts: n/a

Default mySQL Timestamp in php - 08-17-2004 , 03:28 AM






Why is it so difficult to do such a simple thing?

I have a mySQL db where one field has a timestamp in it. And all I want to do
is to display it on a page in a format people can read. Why is it so hard?

Here is what I have ...

<?php echo date('Y-m-j',strtotime($row_rsRefers['ReferralDate'])); ?>

And here is the result .....

Warning: date(): Windows does not support dates prior to midnight (00:00:00),
January 1, 1970 in
E:\koparadmin_main_website_asp\jobsfirst2\client_r eferrals.php on line 110

Someone please?

Thanks,
Brad


Reply With Quote
  #2  
Old   
Joaquim Lopes
 
Posts: n/a

Default Re: mySQL Timestamp in php - 08-17-2004 , 03:54 AM






Brad,

change your code to
<?php echo date('Y-m-j',$row_rsRefers['ReferralDate']); ?>. A timestamp is an int, not a string.
Hope this helps.

Reply With Quote
  #3  
Old   
Brad Lawryk
 
Posts: n/a

Default Re: mySQL Timestamp in php - 08-17-2004 , 04:33 AM



Thanks Jaoquim ..... its getting closer.

But I get a date that is way out of whack?

Date: 2038-01-18 (20040816235259) - should be 2004-08-16 not 2038-01-18?

Reply With Quote
  #4  
Old   
Brad Lawryk
 
Posts: n/a

Default Re: mySQL Timestamp in php - 08-17-2004 , 04:36 AM



Hi Michael,

its a timestamp field ..... see message above for what is happening now.

If I change it to a Date field how do i get the date to automatically be
stored and how will that effect current data?


Reply With Quote
  #5  
Old   
Michael Fesser
 
Posts: n/a

Default Re: mySQL Timestamp in php - 08-17-2004 , 04:45 AM



.oO(Brad Lawryk)

Quote:
Why is it so difficult to do such a simple thing?

I have a mySQL db where one field has a timestamp in it. And all I want to do
is to display it on a page in a format people can read. Why is it so hard?
What date is it? What is the type of the field in the db?

Quote:
Here is what I have ...

?php echo date('Y-m-j',strtotime($row_rsRefers['ReferralDate'])); ?

And here is the result .....

Warning: date(): Windows does not support dates prior to midnight (00:00:00),
January 1, 1970 in
E:\koparadmin_main_website_asp\jobsfirst2\client_r eferrals.php on line 110
You could store the date as DATE or DATETIME and use MySQL functions to
return it formatted.

Micha


Reply With Quote
  #6  
Old   
Michael Fesser
 
Posts: n/a

Default Re: mySQL Timestamp in php - 08-17-2004 , 11:13 AM



.oO(Brad Lawryk)

Quote:
its a timestamp field ..... see message above for what is happening now.

If I change it to a Date field how do i get the date to automatically be
stored and how will that effect current data?
The type TIMESTAMP is OK, but you can't use PHP's date functions on it
(the timestamp that MySQL uses has nothing to do with a Unix timestamp,
which is used by PHP).

You could use the MySQL function DATE_FORMAT() to return a formatted
date instead.

Micha


Reply With Quote
  #7  
Old   
Brad Lawryk
 
Posts: n/a

Default Re: mySQL Timestamp in php - 08-17-2004 , 12:53 PM



okay, keep in mind I am new to mySQL and PHP ....

This is what I have in my SQL:

SELECT referrals.ClientID, referrals.JobOrderID,
DATE_FORMAT(referrals.ReferralDate,'%M %e, %Y'), joborders.ID,
joborders.EmployerName, joborders.EmployerCity, joborders.JobTitle,
joborders.JobLocation
FROM (joborders INNER JOIN referrals ON referrals.JobOrderID=joborders.ID)

And this is what I have to display the date:

<?php echo $row_rsRefers['DATE_FORMAT(referrals.ReferralDate']; ?>

I don't get any arrers, but nothing at all shows up?

Thanks again for your patience
Brad


Reply With Quote
  #8  
Old   
Gary White
 
Posts: n/a

Default Re: mySQL Timestamp in php - 08-17-2004 , 02:55 PM



Brad Lawryk wrote:

Quote:
SELECT referrals.ClientID, referrals.JobOrderID,
DATE_FORMAT(referrals.ReferralDate,'%M %e, %Y'), joborders.ID,
joborders.EmployerName, joborders.EmployerCity, joborders.JobTitle,
joborders.JobLocation
FROM (joborders INNER JOIN referrals ON referrals.JobOrderID=joborders.ID)

Change the above to:
SELECT referrals.ClientID, referrals.JobOrderID,
DATE_FORMAT(referrals.ReferralDate,'%M %e, %Y') as referraldate,
joborders.ID, joborders.EmployerName, joborders.EmployerCity,
joborders.JobTitle, joborders.JobLocation
FROM (joborders INNER JOIN referrals ON
referrals.JobOrderID=joborders.ID)

Quote:
And this is what I have to display the date:

?php echo $row_rsRefers['DATE_FORMAT(referrals.ReferralDate']; ?
Change the above to:

<?php echo $row_rsRefers['referraldate']; ?>


Gary


Reply With Quote
  #9  
Old   
Brad Lawryk
 
Posts: n/a

Default Re: mySQL Timestamp in php - 08-17-2004 , 05:41 PM



Thanks Gary!

That did the trick! Much apprecitaed.

Brad

Reply With Quote
  #10  
Old   
Gary White
 
Posts: n/a

Default Re: mySQL Timestamp in php - 08-17-2004 , 06:59 PM



Brad Lawryk wrote:

Quote:
Thanks Gary!

That did the trick! Much apprecitaed.

You're welcome.


Gary


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.