Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.