Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: working with year in mysql

by Kanji (Parson)
on Dec 16, 2005 at 06:13 UTC ( #517152=note: print w/ replies, xml ) Need Help??


in reply to working with year in mysql

Is isn't clear from your "question" where the problem might be, but there are a few things you can try...

Make sure you quote the year field (eg, '02') as MySQL will helpfully strip the leading zeros off bare numbers (eg, 02).

If you're INSERTing this data using DBI and placeholders, it's possible DBI is misquoting your input.

Using bind_params may help to coerce it otherwise, or you could explicitly pad your input instead so that the absence of quotes on numbers becomes a non-issue (eg, INSERT ... LPAD(?, 2, 0)).

Padding works equally well if you prefer to tackle this on the output side of things, and can be done in your SQL as above (eg, SELECT ... LPAD(...)) or by massaging the results in Perl afterwards (eg, sprintf '%02s', $year_col, but note the use of 's' instead of the more common 'd').

    --k.



Comment on Re: working with year in mysql

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://517152]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2014-09-21 18:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (173 votes), past polls