Heads up: This description was created by AI and might not be 100% accurate.
monday_of_this_week2.rb
This Ruby code snippet demonstrates calculating the date of the previous Monday from the current date and time. The first line gets the current date and time. The second line subtracts the appropriate number of seconds (calculated based on the day of the week) from the current time to obtain the date of the preceding Monday.
Ruby code snippet
today = Time.now
#=> 2025-07-22 13:40:26.512061642 +0000
this_monday = today - (today.wday - 1) * 24 * 60 * 60
#=> 2025-07-21 13:40:26.512061642 +0000
Executed with Ruby 3.4.5
.