i have date stored as type date: y-m-d (eg 2003-05-03)
i want it to be display as
3 May 2003
i tried this
but the result displayed 1 Jan 70PHP Code:$dateStart= date("j M y", strtotime($row['dateStart']));
help
i have date stored as type date: y-m-d (eg 2003-05-03)
i want it to be display as
3 May 2003
i tried this
but the result displayed 1 Jan 70PHP Code:$dateStart= date("j M y", strtotime($row['dateStart']));
help
Last edited by sabahan; 09-16-2009 at 11:58 AM.
It's best to store dates as the number of seconds since 1970, which is the standard format. It's something like 11000000 now, though I forget the number of zeros.
That is what date() is setup to deal with, so you can use that to output how you want and strtotime to make that.
I'm not sure about why it's not working, but there are probably ways to set strtotime to understand y-m-d.
But again, it's best to just always start with the default date() input (as just number of seconds since 1970) and it'll always work.
Hope this helps.
(Specifically about your code-- the output is correct, but the input is not. strtotime is not giving a reasonable value, so date() is assuming 0 seconds since 1970-- so you get 1 Jan 1970.)
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
sabahan (09-16-2009)
Your code looks like it should work, maybe check how you've stored it in the database, this definitely works:
PHP Code:$datetime = '2003-05-03';
echo date('j M y', strtotime($datetime));
// Outputs 3 May 03
sabahan (09-16-2009)
thanks..the date in db is correct and is stored as 2003-05-03
i use it like this and now it works
PHP Code:
echo "" . date('j M Y', strtotime($row['dateStart'])) . "";
but i wonder why when i used it like this..the date is displayed as 1 Jan 1970
PHP Code:$mydate= date('j M Y', strtotime($row['dateStart']));
echo $mydate;
need another help......
i have dateStart and dateEnd
both stored as xxxx-xx-xx format in db eg 2009-09-16
i displayed the date in my page as 16 Sep 09
example the date duration is 16 Sep 09 - 18 Sep 09PHP Code:echo "" . date('j M y', strtotime($row['dateStart'])) . "";
echo " - ";
echo "" . date('j M y', strtotime($row['dateEnd'])) . "";
i want to display it as 16 - 18 Sep 09
and if the date is 29 Jan 09 - 3 Feb 09
i want to display it as 29 Jan - 3 Feb 09
is this possible ?
ok solved
PHP Code:
$month1 = date('M', strtotime($row['dateStart']));
$month2 = date('M', strtotime($row['dateEnd']));
if ($row[dateEnd]=='0000-00-00')
{
echo date('j M y', strtotime($row['dateStart']));
}
else if ($month1 == $month2) {
echo date('j', strtotime($row['dateStart'])) . ' - ' . date('j M y', strtotime($row['dateEnd']));
} else {
echo date('j M y', strtotime($row['dateStart']) . ' - ' . date('j M y', strtotime($row['dateEnd']);
}
Bookmarks