Jump to content

strtotime() problems


Akira

Recommended Posts

Hey all,

 

I just don't get it.

I have dates stored in my DB in the following format; 16/06/2008

 

I want to convert them to; 16 June 2008.

 

using following to do so;

$date = strftime("%d %B %Y",strtotime("$row[enddate]"));

 

Now, i just don't get it... cause the strotime function doens't make a timestamp.

Output = empty.

 

but when I use a normal string, like;

$date = strftime("%d %B %Y",strtotime("16/06/2008"));

 

No problems.

 

What am i doing wrong here??

Tried every combination;

strtotime("$row[enddate]")
strtotime($row['enddate'])
strtotime($row[enddate])

 

Running 2003 Server, IIS 6, PHP 5.2.

 

Hope somebody has an anwser, out of ideas ^^

 

Link to comment
Share on other sites

Thanks for replying!

 

$date = strftime("%d %B %Y",strtotime($row['enddate']));

 

Still no output.

 

And yes, at first i used;

print $row['enddate'];

 

but to give it a better look, I wanted to convert the date.

So i'm sure that the $row['enddate'] is filled :)

Link to comment
Share on other sites

The strtotime() function doesn't like dates in the format dd/mm/yyyy, so you need to convert that date into a format it likes: mm/dd/yyyy:

<?php
list($d,$m,$y) = explode('/',$row['enddate']);
$date = strftime("%d %B %Y",strtotime("$m/$d/$y"));
?>

 

It would be much better if you stored the date in your DB as YYYY-MM-DD, then you could take advantage of the many date features of mysql.

 

Ken

Link to comment
Share on other sites

When this code

<?php
$date = strftime("%d %B %Y",strtotime("16/06/2008"));
echo $date;
?>

 

outputs "01 January 1970 ", then I'd say you have problems

 

hehe, nope, that code gives a nice output of 16 June 2008, like i said, no problems their :)

Link to comment
Share on other sites

The strtotime() function doesn't like dates in the format dd/mm/yyyy, so you need to convert that date into a format it likes: mm/dd/yyyy:

<?php
list($d,$m,$y) = explode('/',$row['enddate']);
$date = strftime("%d %B %Y",strtotime("$m/$d/$y"));
?>

 

It would be much better if you stored the date in your DB as YYYY-MM-DD, then you could take advantage of the many date features of mysql.

 

Ken

 

Hey Ken,

 

Thanks heaps for this!

Added your code, and it works now :D

 

Weird that this isn't well documented at php.net.

 

 

 

 

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.