date format

Y

Yasaswi Pulavarti

I have a text file I need to load into MySQL database. In the text
file the date is shown as mm/dd/yyyy format. However I need to enter
the date in MySQL native yyyy-mm-dd format. How can I change
formatting without using substring function?
Thanks,
Yasaswi
 
T

Tad McClellan

Yasaswi Pulavarti said:
I have a text file I need to load into MySQL database. In the text
file the date is shown as mm/dd/yyyy format. However I need to enter
the date in MySQL native yyyy-mm-dd format. How can I change
formatting without using substring function?


What is wrong with the substr() function?


s#(\d\d)/(\d\d)/(\d\d\d\d)#$3-$1-$2#; # untested
 
G

Gunnar Hjalmarsson

Yasaswi said:
I have a text file I need to load into MySQL database. In the text
file the date is shown as mm/dd/yyyy format. However I need to enter
the date in MySQL native yyyy-mm-dd format. How can I change
formatting without using substring function?

s|(\d\d)/(\d\d)/(\d{4})|$3-$1-$2|
 
G

Gregory Toomey

Yasaswi said:
I have a text file I need to load into MySQL database. In the text
file the date is shown as mm/dd/yyyy format. However I need to enter
the date in MySQL native yyyy-mm-dd format. How can I change
formatting without using substring function?
Thanks,
Yasaswi

According to http://dev.mysql.com/doc/mysql/en/Loading_tables.html ,
even the mysql data loader only accepts yyyymmdd.

Write a small Perl script to reformat the dates.

gtoomey
 
E

Eric Amick

I have a text file I need to load into MySQL database. In the text
file the date is shown as mm/dd/yyyy format. However I need to enter
the date in MySQL native yyyy-mm-dd format. How can I change
formatting without using substring function?

MySQL has a STR_TO_DATE function that can do the conversion for you:

STR_TO_DATE('06/12/2004', '%m/%d/%Y')
 
E

Eric J. Roode

(e-mail address removed) (Yasaswi Pulavarti) wrote in
I have a text file I need to load into MySQL database. In the text
file the date is shown as mm/dd/yyyy format. However I need to enter
the date in MySQL native yyyy-mm-dd format. How can I change
formatting without using substring function?
Thanks,
Yasaswi

This is a homework problem, isn't it? :)

--
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,430
Latest member
7dog123

Latest Threads

Top