date conversion for MySQL

Post everything else here

Moderators: Website/Forum Admins, Other/Off Topic Moderators

rf
Posts: 30
Joined: Wed Apr 05, 2006 10:16 pm

date conversion for MySQL

Postby rf » Tue Aug 15, 2006 1:06 pm

I need a grep or FSR or AWK or some miniprogram/statement that will convert 08/16/2006 date format into 2006-08-16 format in a text file. I am sure this would take an expert 30 seconds to do!

Thanks much :D

rf
User avatar
deww
Posts: 125
Joined: Fri Jul 18, 2003 7:17 pm

Postby deww » Tue Aug 15, 2006 2:20 pm

You can use date...
date +%Y-%m-%d
rf
Posts: 30
Joined: Wed Apr 05, 2006 10:16 pm

Postby rf » Tue Aug 15, 2006 4:08 pm

User avatar
deww
Posts: 125
Joined: Fri Jul 18, 2003 7:17 pm

Postby deww » Tue Aug 15, 2006 4:59 pm

rf
Posts: 30
Joined: Wed Apr 05, 2006 10:16 pm

Postby rf » Tue Aug 15, 2006 5:23 pm

User avatar
munky
Site Admin
Posts: 826
Joined: Wed Jul 02, 2003 4:54 pm
Location: Phoenix AZ
Contact:

Postby munky » Tue Aug 15, 2006 5:32 pm

In God we trust,
Everyone else must have an X.509 certificate.
rf
Posts: 30
Joined: Wed Apr 05, 2006 10:16 pm

Postby rf » Tue Aug 15, 2006 6:51 pm

User avatar
munky
Site Admin
Posts: 826
Joined: Wed Jul 02, 2003 4:54 pm
Location: Phoenix AZ
Contact:

Postby munky » Wed Aug 16, 2006 12:15 am

man awk

-F defines what the spacer is

-F"/" means your line has only 3 parts ("Some Name 1023 01" would be $1)

cat yourfile.txt | perl -e 'while(<>){chomp; $_ =~ s/(\d{1,2})\/(\d{1,2})\/(\d{4})/\3-\1-\2/; print "$_\n";}'
In God we trust,

Everyone else must have an X.509 certificate.
rf
Posts: 30
Joined: Wed Apr 05, 2006 10:16 pm

Postby rf » Wed Aug 16, 2006 12:30 am

Followup: :D

Thanks for listening and responding. In FSR this program worked perfectly!

:file named date.fsr
:program to change date from mm/dd/yyyy format to yyyy-mm-dd format
"{[0-9][0-9]}/{[0-9][0-9]}/{[0-9][0-9][0-9][0-9]}" "{3}-{1}-{2}" -c

It is a DOS program! I am glad we still have DOS!

Thank you :D

rf
User avatar
deww
Posts: 125
Joined: Fri Jul 18, 2003 7:17 pm

Postby deww » Wed Aug 16, 2006 3:04 am

Woops! Guess I should actually read the actual post! :D *deletes his other posts*

Return to “Off Topic”

Who is online

Users browsing this forum: No registered users and 0 guests