format a date in to the format 'yyyy-mm-dd' in ruby

To format a date into the ISO 8601 format 'yyyy-mm-dd' in Ruby, you can use the strftime method. Here's an example:

main.rb
date = Date.today
formatted_date = date.strftime("%F")
puts formatted_date
75 chars
4 lines

This will output the current date in the 'yyyy-mm-dd' format:

main.rb
2021-04-15
11 chars
2 lines

The %F format specifier is a shortcut for %Y-%m-%d, which represents the year, month, and day of the month, separated by hyphens. You can also use other format specifiers to customize the output.

gistlibby LogSnag