Unix Technical Forum

date format trouble

This is a discussion on date format trouble within the MySQL forums, part of the Database Server Software category; --> > SET start_date=STR_TO_DATE(@date_as_string,'%m/%d/%y'); Dates have 4 digits in your data, right? %y and %Y are different. gordon/(none)> select str_to_date('11/29/1999', ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 02-28-2008, 08:34 AM
Gordon Burditt
 
Posts: n/a
Default Re: date format trouble

> SET start_date=STR_TO_DATE(@date_as_string,'%m/%d/%y');

Dates have 4 digits in your data, right? %y and %Y are different.

gordon/(none)> select str_to_date('11/29/1999', '%m/%d/%y');
+---------------------------------------+
| str_to_date('11/29/1999', '%m/%d/%y') |
+---------------------------------------+
| 2019-11-29 |
+---------------------------------------+
1 row in set, 1 warning (0.00 sec)

gordon/(none)> show warnings;
+---------+------+----------------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------------+
| Warning | 1292 | Truncated incorrect date value: '11/29/1999' |
+---------+------+----------------------------------------------+
1 row in set (0.00 sec)

gordon/(none)> select str_to_date('11/29/1999', '%m/%d/%Y');
+---------------------------------------+
| str_to_date('11/29/1999', '%m/%d/%Y') |
+---------------------------------------+
| 1999-11-29 |
+---------------------------------------+
1 row in set (0.01 sec)


>This gets to examine the data, so I guess the syntax is OK. But I
>still get an error about the date. This time, the error is "Truncated
>incorrect date value: "11/22/1999"


%Y and %y are different.

>instead of trying to load it into @var1? Do the names in the list in
>the LOAD DATA statement have to be provided in the order the
>corresponding columns were created in the table?


I doubt it. That would make listing the names rather pointless.

>If not, I can load
>the data first, and that with the data going into a column of type
>char[10], and then run an UPDATE statement in which the SET start_date
>clause above is invoked. Right?


Yes. But fix your format first.

Gordon L. Burditt
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:28 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com