|
|||||||||||
|
Re: inserting date into mysql
From: Dodger <el.dodgero(at)gmail.com>
Date: Wed Oct 31 2007 - 20:37:10 EDT
SET sdate = '2007-1-1'
Reformat your date to the ones MySQL accepts. "Although MySQL tries to interpret values in several formats, dates always must be given in year-month-day order (for example, '98-09-04'), rather than in the month-day-year or day-month-year orders commonly used elsewhere (for example, '09-04-98', '04-09-98')." http://dev.mysql.com/doc/refman/5.1/en/date-and-time-types.html If you have screwy American style dates and need to reformat them first, do that in your code...
my $dt = '1/1/2007';
SET sdate = ?
Generally though, storing dates in the format of descending order of temporal magnitude is a good idea and has reasons it is. Namely because: YYYY-MM-DD hh:mm:ss is readily sortable as a number simply by stripping out any non-digits to make: YYYYMMDDhhmmss Whereas something like hh:mm:ss, MM/DD/YYYY is not. Consider two dates: the 19th of October, 1972 and the 3oth of April, this year: 19721019000000 < 20070430000000 <-- TRUE
Try 'em the other way and you get:
So why make it harder? BTW of course, if SELECT COUNT(*) WHERE c=1 returns 0, it won't do anything anyway. (BTW, Baron Schwartz... WTH was with that answer you gave? Didn't you know what the poster meant? Whether they did an UPDATE or an INSERT that date would still do the wrong thing, and while it may not have been an INSERT statement, technically, if the date was not already stored in the table, the data would have been inserted into it by an update -- little 'i' insert -- in the sense that it wasn't in it before and now it is. That's like someone saying 'I can't comb my hair' and demonstrating with a brush, and telling them it's because they're not using a comb when the real reason is they have a bad uberfrizzy perm or they're bald or something.) -- Dodger On 31/10/2007, Kiran AnnaiahReceived on Wed Oct 31 20:38:57 2007 This archive was generated by hypermail 2.1.8 : Fri Jul 04 2008 - 00:27:23 EDT |
||||||||||
|
|||||||||||