I'm working with SQL, and I need to get the date I parsed a given into a yyyy-mm-dd format into the database. I can get the date into the format I wish using the following subroutine (snipped from my code). Unfortunately, the month seems to be off by one. If I parse a file on February 13, 2001, It gets returned as "2001-01-13" which would be incorrect. I checked my system time, and everything is okay. Does anyone have any ideas of what I missed?
#!/usr/bin/perl
use strict;
my $date_parsed = get_date();
print "Date Parsed: $date_parsed\n";
# gets parse-time date for release date
sub get_date {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtim
+e(time);
$year += 1900;
($mon, $mday) = (sprintf('%02d', $mon), sprintf('%02d', $mday));
return $year."-".$mon."-".$mday;
};
As I said, the script returns "2001-01-13" if I ran the script on February 13th. I guess I could always add one to the month -- but I want to make sure it isn't something I did wrong otherwise.
--Coplan
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.