|
Posted by hennie on 01/17/07 02:25
Thanks :)
"Kim Andrι Akerψ" <kimandre@NOSPAMbetadome.com> schreef in bericht
news:514oclF1ij38qU1@mid.individual.net...
> hennie wrote:
>
>> How can i convert a date in text format into a date format that is
>> accepted by msql?
>>
>> I have 3 values for day, month and year
>>
>> I combine them to a date string $date1=$year."-".$month."-".$day;
>>
>> How do i go further to make $date1 suitable for mysql?
>
> The correct date format for a DATE or DATETIME field in MySQL is
> 'YYYY-MM-DD' (year, month, date) or 'YYYY-MM-DD HH:MM:SS' (year, month,
> date, hours, minutes, seconds - in 24-hour format), in that order, so
> there shouldn't be anything more to it than just that.
>
> However, to be absolutely sure, though, I'd do it like this:
>
> $date1 = sprintf("%04d-%02d-%02d", intval($year), intval($month),
> intval($day));
>
> http://php.net/function.sprintf
> http://php.net/function.intval
> http://dev.mysql.com/doc/refman/4.1/en/datetime.html
>
> --
> Kim Andrι Akerψ
> - kimandre@NOSPAMbetadome.com
> (remove NOSPAM to contact me directly)
[Back to original message]
|