Ruby code to get the date of next Monday (or any day of the week)

前端 未结 7 473
再見小時候
再見小時候 2020-12-02 14:36

Given an input of, for example,

day = \'Monday\'

how can I calculate the date of day?

def date_of_next(day)
           


        
7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 15:14

    If you are using rails you can use Date.today.sunday for Sunday or Date.today.monday for Monday. And then Date.today.sunday - 1.day for Saturday etc.

提交回复
热议问题