Reply to Re: how to convert text into mysql date format?

Your name:

Reply:


Posted by Kim Andrι Akerψ on 01/16/07 19:46

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]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация