Closed Thread Icon

Topic awaiting preservation: PHP date into MySQL trouble (Page 1 of 1) Pages that link to <a href="" title="Pages that link to Topic awaiting preservation: PHP date into MySQL trouble (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: PHP date into MySQL trouble <span class="small">(Page 1 of 1)</span>\

Paranoid (IV) Inmate

From: Sydney, Autralia
Insane since: Jun 2004

posted posted 11-04-2004 11:01


i have a form which gets the date via 3 drop down menus (1 each for day, month, year).

how do i take a date string in php, ie $date = date("d/m/Y"); and convert it into a format that MySQL understands?

i have been searching for info on this but all i can find is the mysql function now() which i dont need.

can someone help out a little with a link or tut or something?????

thanks in advance.

10/6 Web Solutions

New site online now!

For all your business and commercial web site needs.

Contact 10/6 Web Solutions today for an evaluation of your requirements.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 11-04-2004 14:14

first you turn your date into a timestamp via php->strtotime()
Then you look up the syntax for date values in mysql (see mysql->date) and use php->date() to format it that way.

so long,

->Tyberius Prime

Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 11-07-2004 00:33

if you've got three seperate drop-downs for Day, month and year why not simply arrange them backwards? MySQL's date fields read YYYYMMDD I believe, so simply make sure the your date values for month and day have leading zeroes for all values under 10 and thne just concatonate them and insert. On my MySQL test server that works for me.

Justice 4 Pat Richard

Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 11-07-2004 00:37

To find the date format, why don't you simply insert a date using the now() function, and then retrieve it to see how the dates are actually formated in MySql ? Then you'll know how to format your dates in PHP before inserting them in a table. That's not hard.

(Edited by poi on 11-07-2004 00:55)

Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 11-07-2004 04:30

I'd like to second skaarrj's suggestion. It's a very simple matter, since must be grabbing those values seperately to simply combine them in the proper order - $date = "$year-$month-$day" where $year $month and $day are the values captured from the form (mysql will actually accept it with or without the dashes....but I like the dashes....).

« BackwardsOnwards »

Show Forum Drop Down Menu