Getting current date

L

laredotornado

Hi,

How do I get the current date in the form "YYYY-MM-DD".

Thanks, - Davegro
 
L

Lloyd Linklater

My clunky way:

n = Time.now
d = Time.gm(n.year, n.month - 1, n.day)

p d

=> Tue Aug 12 00:00:00 UTC 2008
 
L

Lloyd Linklater

ok. Improvement time:

n = Time.now
if n.month == 12
d = Time.gm(n.year - 1, 12, n.day)
else
d = Time.gm(n.year, 1 - 1, n.day)
end


There has GOT to be a better way but I did not want you to have nothing.
:)
 
L

Lloyd Linklater

dang typos

n = Time.now
if n.month == 1
d = Time.gm(n.year - 1, 12, n.day)
else
d = Time.gm(n.year, 1 - 1, n.day)
end
 
L

Lloyd Linklater

I put the testing code in and I feel REALLY stupid. If it is still
wrong, I am going to hide under a rock until everyone forgets that I did
this.

n = Time.now
if n.month == 1
d = Time.gm(n.year - 1, 12, n.day)
else
d = Time.gm(n.year, n.month - 1, n.day)
end
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top