Syntactic Confectionery Delight | |
PerlMonks |
How do you format dates for entry into MySql?by glamring (Initiate) |
on Sep 01, 2001 at 00:01 UTC ( [id://109526]=perlquestion: print w/replies, xml ) | Need Help?? |
glamring has asked for the wisdom of the Perl Monks concerning the following question:
Questions:
1. How do you take a date in the form 'Month YYYY' and convert it to the form 'YYYY-MM-DD'? (I am assuming that DD will be 00 since I do not have any days to convert) Example: March 1990 => 1990-03-00 2. How do you reverse the process, and convert from'YYYY-MM-DD' to 'Month YYYY'? Example: 1990-03-00 => March 1990 Background: I am using the CueCat sample code from Brent Michalski (moderator of the Perl channel for Dr. Dobb's Online) to catalog my book collection. The code is located at: Roll Your Own Data Capture This code in and of itself works just fine, but I want to modify the code to reformat the date into the format expected by MySql, so I can store the data in the table with a DATE datatype, instead of VARCHAR, as I am using now. (I want to be able to sort each author's work in chronological order, so Book 1 of a trilogy will show up before Book 2, etc) I am assuming that since the code already parses out the date and puts it into a variable, I just need to write a subroutine that will reformat this value. I just don't know what Regular Expression or function to use to do the conversion. I've looked at Date::Ordinal, which looks like what I need, but I don't understand how to use it.
Back to
Seekers of Perl Wisdom
|
|