R
Rong
When I do this:
dob="05/01/1968"
x=Date.parse(dob)
x.month
I get 1 instead of 5.
How do I do this?
dob="05/01/1968"
x=Date.parse(dob)
x.month
I get 1 instead of 5.
How do I do this?
When I do this:
=20
dob=3D"05/01/1968"
x=3DDate.parse(dob)
x.month
=20
I get 1 instead of 5.
How do I do this?
=20
When I do this:
dob="05/01/1968"
x=Date.parse(dob)
x.month
I get 1 instead of 5.
How do I do this?
Well, it's not a bug or something. The rest of the world uses day/month/year so that is the default that the Date.parse method uses.
The easiest solution (and the best way to do this IMO) is to just feed the method "01/05/1968" instead of "05/01/1968".
If for some reason, you HAVE to have the m/d/y format, you could just use a regexp. Could be something like this, but note, it's not really the best regexp, just something I came up with now (you can use rubular.com to figure out ruby regexps easily):
dob = "05/01/1968"
dob =~([01]\d)\/([0-3]\d)\/((19|20)\d\d)
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.