the closest Sunday before given date with JavaScript

前端 未结 4 1206
旧时难觅i
旧时难觅i 2021-01-04 07:18

I need to know the date for last Sunday for given date in php & javascript

Let\'s have a function give_me_last_Sunday



        
4条回答
  •  被撕碎了的回忆
    2021-01-04 07:30

    Ok so this is for JavaScript only. You have an input that you need to extract the month, date, and year from. The following is just partly an answer then on how to get the date:

    
    

    So the setFullYear function sets the myDate to the date specified where the first four digits is the year, the next are is the month (0= Jan, 1= Feb.,...). The last one is the actually date. Then the above code gives you the date of the Sunday before that. I am guessing that you can add more code to get the month (use getMonth() method). Here are a few links that might be helpful

    • http://www.w3schools.com/js/js_obj_date.asp
    • http://www.w3schools.com/jsref/jsref_setFullYear.asp
    • http://www.w3schools.com/jsref/jsref_getMonth.asp

    (You can probably find the other functions that you need)

    I hope this helps a bit even though it is not a complete answer.

提交回复
热议问题