Jump to content

[SOLVED] strtotime


eon201

Recommended Posts

Hi,

 

Im trying to use the strtotime function to convert this a date in this format ( 2007 11 11 20:34:56 ) to a unix timestamp.

 

It should work (I think) but doesnt. What have I done wrong with the below code??  :-[

 

$date = strtotime($date);

 

Thanks in advance. Eon201.

 

Link to comment
Share on other sites

lol. sorry

so date in the array is in this format yyyy-mm-dd

whilst time is in this format hh:mm:ss

 

$time = $overall_array['time'];

$date = $overall_array['date'];

$date = $date. " ". $time;

$date = substr_replace($date, " ", 4, 1);

$date = substr_replace($date, " ", 7, 1);

 

$date = '2007 11 11 20:34:56';

 

Hope that helps clear things up!

Link to comment
Share on other sites

MySQL has a unix_timestamp() function that will convert a MySQL datetime format to a unix_timestamp like this...

 


$query = mysql_query ("SELECT unix_timestamp('2007-11-15 12:00:00') AS timestamp");
$date = mysql_fetch_assoc ($query);
echo $date['timestamp'];

 

The parameter of the function can also be a database field like this...

 


$query = mysql_query ("SELECT unix_timestamp(date) AS timestamp");
$date = mysql_fetch_assoc ($query);
echo $date['timestamp'];

Link to comment
Share on other sites

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.