SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: Date Format in mysql
-
Jun 14, 2001, 20:39 #1
- Join Date
- May 2001
- Location
- Lahore pakistan
- Posts
- 1
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Date Format in mysql
i am taking date input from user in a form . User will enter date in mm-dd-yyyy but mysql supports yyyy-mm-dd . Now what is way to change input date to mysql standard format . Like to_date(format,date) function in oracle.
-
Jun 14, 2001, 21:31 #2
- Join Date
- Mar 2001
- Location
- Medina, OH
- Posts
- 440
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well assuming you are running the form with PHP, sure.
Just use the date function. (freddydoesphp will probably come along and give you an easier way but for now, here ya go.
)
First convert the users' input into a timestamp and then convert that into the MySQL format.
So,Code:$userdateinput = str_replace("-",",",$userdateinput); $timestamp = date("U",mktime(0,0,1,$userdateinput)); $mysqldate = date("Y-m-d",$timestamp);
Kevin
-
Jun 14, 2001, 21:44 #3
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
No not at all in fact tubedogg that is a nice way of doing that(the str_replace, I hadn't seen it done that way), except unless you need both of those variables $timestamp and $mysqldate, if not you could simply combine them and save maybe an nth of a second. But thats just me being picky.
$mysqldate = date("Y-m-d",mktime(0,0,1,$userdateinput));Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Jun 14, 2001, 22:11 #4
- Join Date
- Mar 2001
- Location
- Medina, OH
- Posts
- 440
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hehe Thanks freddy
Now that I got my ego boost for the night...
Kevin
Bookmarks