469,604 Members | 2,377 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,604 developers. It's quick & easy.

String to mysql date field

How do I convert a string into a value I can upload to mysql date field.
Specifically, I have a user select a month, day and year from
drop-downs, then I want them submitted to one date field. Thanks!
Steve.
Jul 17 '05 #1
3 3112
Noyb wrote:
How do I convert a string into a value I can upload to mysql date field.
Specifically, I have a user select a month, day and year from
drop-downs, then I want them submitted to one date field. Thanks!
Steve.


You want to convert a string to a unix timestamp, then you can use the functions
in mysql to convert the timestamp to mysql native.

http://www.php.net/manual/en/function.strtotime.php

Also, use Mishoo's dHTML calendar: http://sourceforge.net/projects/jscalendar/
Jul 17 '05 #2
I noticed that Message-ID: <4Igpc.26291$5a.24525@okepread03> from Jeff
Rodriguez contained the following:
How do I convert a string into a value I can upload to mysql date field.
Specifically, I have a user select a month, day and year from
drop-downs, then I want them submitted to one date field. Thanks!
Steve.


You want to convert a string to a unix timestamp, then you can use the functions
in mysql to convert the timestamp to mysql native.


Why, when he can arrange the dropdown boxes to provide a suitable date?
Say the boxes return year month and day

function make_mysql_date($y,$m,$d){
$array = array($y,$m,$d);
$mysql_date = implode("/", $array);
return $mysql_date;
}

Not that I usually bother with MySql's date format these days. Mostly I
simply store a Unix timestamp.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3
>> How do I convert a string into a value I can upload to mysql date field.
Specifically, I have a user select a month, day and year from
drop-downs, then I want them submitted to one date field. Thanks!
Steve.


You want to convert a string to a unix timestamp, then you can use the
functions
in mysql to convert the timestamp to mysql native.


This doesn't work very well for some applications. It's problematical
for anything dealing with a date of birth of a living person, and
even more problematical for genealogy. (Some implementation treat
a UNIX time_t as signed, yielding a time range of about 1901-2038,
which is too small. Even worse is the ones that interpret it as
unsigned, giving a time range of about 1970-2106, which is really
bad if your application deals with people receiving retirement
benefits).

Even the MySQL native date format has problems if you can trace
your ancestors back more than about 2,004 years.

Gordon L. Burditt
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Albert Ahtenberg | last post: by
2 posts views Thread by Yulia Yegenov | last post: by
10 posts views Thread by Bob Bedford | last post: by
2 posts views Thread by hph | last post: by
11 posts views Thread by walterbyrd | last post: by
6 posts views Thread by Geoff Cox | last post: by
8 posts views Thread by Tony B | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.