[thelist] Date & time formatting
Max Schwanekamp
lists at neptunewebworks.com
Mon Apr 17 11:11:55 CDT 2006
Santilal Parbhu wrote:
> > I want to be able to enter times and
> > dates in a format like say "12:00pm May 21",
I wrote:
> PHP's strtotime() may help you allow some more flexible date
> input formats.
Santilal Parbhu wrote:
> I have tries this but I can't make it accept the input format
> dd/m/y. This is the code I am using to store the date.
> $year = '/06';
> $entered_date = "{$HTTP_POST_VARS['matchdate']}";
> $ddate = $entered_date . $year;
> $ddate = strtotime("$ddate");
> print"$ddate";
> You can see that actually I am inputing the format dd/mm.
> The year is concatenated onto the end of the date. I am
> posting the date to mysql via a form.
Ah, strtotime() has its limitations! The format you originally supplied
would work fine, but the dd/m format won't work. If you're enforcing that
format, you might simply do:
$dateParts = explode('/',$entered_date);
$ddate = strtotime($dateParts[1].'/'.$dateParts[0].'/'.$year);
Again, store the result as a unix timestamp in MySQL. Makes date-time
operations a lot easier down the road.
--
Max Schwanekamp
http://www.neptunewebworks.com/
More information about the thelist
mailing list