Jump to content

[SOLVED] Trouble with Time and Date


MasterACE14

Recommended Posts

Hey,

 

I'm having some trouble with the Time and Date, I'm not sure if I am inserting the right time/date into the database in a Integer column. But I'm also not 100% sure that I am echo'ing the time/date right either.

 

Basically what I do is insert time(); into the database, and then retrieve it and format it with this code:

<?php
// workout Time
		$datetime = $row["time"];
		$year = substr( $datetime, 0, 4 );
		$mon = substr( $datetime, 4, 2 );
		$day = substr( $datetime, 6, 2 );
		$hour = substr( $datetime, 8, 2 );
		$min = substr( $datetime, 10, 2 );
		$sec = substr( $datetime, 12, 2 );
		$orgdate = date("F j, Y",
		mktime( $hour, $min, $sec, $mon, $day, $year ) );

// and I echo this:
echo date("F j, Y", strtotime($datetime));

 

but it keeps echoing

December 31, 1969

 

I'm not sure if I'm inserting the incorrect time/date into the database, or if I'm echoing is incorrect?

 

any help is greatly appreciated.  :)

 

Regards ACE

Link to comment
https://forums.phpfreaks.com/topic/90128-solved-trouble-with-time-and-date/
Share on other sites

Is that PHP time() or SQL time()? Can't remember if they are the same. If it's PHP just do:

 

<?php
// workout Time
		$datetime = $row["time"];
		$orgdate = date("F j, Y", $datetime);

echo $orgdate;

Not sure why you used strtotime when the time column in the db is an int.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.