In Perl you can do:
my $current_time = DateTime->now(); my $mdy = $current_time->mdy("/");
What's the easiest way to do this in Ruby?
Two steps: You need to convert your string into Date object. For that, use Date#strptime . You can use Date#strftime to convert the Date object into preferred format.
Go to Format Cells > Custom Enter mm/dd/yyyy in the available space. Or you can use : Select a blank cell next to your date, for instance. I1, and type this formula =TEXT(G1, "yyyy-mm-dd"), and press Enter key, then drag AutoFill handle over the cells needed this formula.
Ruby | Time strftime() function Time#strftime() is a Time class method which returns the time format according to the directives in the given format string. Syntax: Time.strftime() Parameter: Time values. Return: time format according to the directives in the given format string.
The strftime
method can be used to format times:
Time.now.strftime("%m/%d/%Y")
I wrote a gem to help with formatting dates, and keeping your views DRY (not having to strftime every time you want to format dates).
Check it out at: http://github.com/platform45/easy_dates
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With