If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > need help with mysql date and php

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-02-04, 18:12
noamkrief noamkrief is offline
Registered User
 
Join Date: Dec 2003
Posts: 61
need help with mysql date and php

i want people to be able to type in the date in normal form:
for example:
12/25/2003
This needs to be converted to mysql 2003-12-25

Here's my code:
$date_input = $DATE;
$date_output = preg_replace('-^(\d\d)/(\d\d)/(\d\d\d\d)$-', "\\3-\\1-\\2", $date_input);
It works
My problem is that the day has to be 2 digits, and so does the month. Therefore:

2/2/2004 does not work. The user must type in 02/02/2004

so i tried:

$DATE = date("d/m/Y");

$date_input = $DATE;
$date_output = preg_replace('-^(\d\d)/(\d\d)/(\d\d\d\d)$-', "\\3-\\1-\\2", $date_input);

That didn't work...
Can anyone help?

Thanks
Noam
Reply With Quote
  #2 (permalink)  
Old 01-02-04, 18:19
roga roga is offline
Registered User
 
Join Date: Jan 2004
Location: Germany
Posts: 17
lol
See your other topic, there is a function that does exactly that.

http://www.php.net/strtotime

PHP Code:
$input_date "2/2/2004";

$unix_timestamp strtotime($input_date);
$mysql_compatible_date date("Y-m-d"$unix_timestamp);

// of course you can do it in a single statement
$mysql_compatible_date date("Y-m-d"strtotime($input_date)); 
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On