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 > Date format

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-08-04, 13:43
exdter exdter is offline
Registered User
 
Join Date: Aug 2003
Posts: 328
Date format

I am uploading data into a MySql table from a VB application. I want to get today's date using Date. When I look at the results, what is 3/8/2004 in my VB app, is now 2003-08-20. I am guessing this is a formatting problem. Any ideas?
Thanks
Reply With Quote
  #2 (permalink)  
Old 03-08-04, 14:09
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
when you give mysql a date, it must be in year-month-day sequence

you could upload your dates into a varchar(10) column, alter the table to add a new column with DATE or DATETIME datatype, then update the table and use substring expressions to pull the pieces out of the varchar column to update the date column

Code:
update yourtable 
   set datecolumn 
     = concat_ws('/'
           , substring(varcharcolumn 
                   from locate('/',varcharcolumn,4)+1)
           , left(varcharcolumn,locate('/',varcharcolumn,4)-1)
                )
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-08-04, 14:11
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
oh, wait a sec

all you want is today's date?

use the built-in mysql CURRENT_DATE function
Code:
insert 
  into yourtable
     ( foo
     , bar
     , datecolumn )
values
     ( 'qwerty'
     , 'asdfg'
     , current_date )
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 03-08-04, 14:14
exdter exdter is offline
Registered User
 
Join Date: Aug 2003
Posts: 328
Thanks for your help. I just changed the type in my SQL table to varchar and it works fine.
Reply With Quote
  #5 (permalink)  
Old 03-08-04, 14:15
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
yeah, but don't forget to convert it to DATE

otherwise you will not be able to do any date arithmetic on it

e.g. where datecolumn between '2004-03-08' and '2004-03-31'
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 03-08-04, 14:16
exdter exdter is offline
Registered User
 
Join Date: Aug 2003
Posts: 328
Good point!!! Thanks.
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