Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. date -d @$(( $(date -d $(date -d @$(( $(date +%s) + 2678400 )) +%Y%m01) +%s) - 604800 )) +%d
  2.  
  3. $ cal | awk '/^ *[0-9]/ { d=$1 } END { print d }'
  4. 25
  5.  
  6. $ cal
  7. December 2016
  8. Su Mo Tu We Th Fr Sa
  9. 1 2 3
  10. 4 5 6 7 8 9 10
  11. 11 12 13 14 15 16 17
  12. 18 19 20 21 22 23 24
  13. 25 26 27 28 29 30 31
  14.  
  15. #!/bin/bash
  16.  
  17. # print last Sundays for 2016 and 2017
  18.  
  19. for y in {2016..2017}
  20. do
  21. for m in {1..12}
  22. do
  23. first_day_of_month=$y/$m/1
  24. days_in_month=$(date +%d -d "$first_day_of_month month day ago")
  25. day_of_week_of_last_day=$(date +%w -d "$first_day_of_month month day ago")
  26. last_sunday=$(date -d "$first_day_of_month $days_in_month day $[1+$day_of_week_of_last_day] day ago")
  27. echo $last_sunday
  28. done
  29. echo
  30. done
  31.  
  32. # print last Sunday for current month
  33.  
  34. first_day_of_month=$(date +%m/1)
  35. days_in_month=$(date +%d -d "$first_day_of_month month day ago")
  36. day_of_week_of_last_day=$(date +%w -d "$first_day_of_month month day ago")
  37. last_sunday=$(date -d "$first_day_of_month $days_in_month day $[1+$day_of_week_of_last_day] day ago")
  38. echo $last_sunday
  39.  
  40. Sun Jan 31 00:00:00 GMT 2016
  41. Sun Feb 28 00:00:00 GMT 2016
  42. Sun Mar 27 00:00:00 GMT 2016
  43. Sun Apr 24 00:00:00 BST 2016
  44. Sun May 29 00:00:00 BST 2016
  45. Sun Jun 26 00:00:00 BST 2016
  46. Sun Jul 31 00:00:00 BST 2016
  47. Sun Aug 28 00:00:00 BST 2016
  48. Sun Sep 25 00:00:00 BST 2016
  49. Sun Oct 30 00:00:00 BST 2016
  50. Sun Nov 27 00:00:00 GMT 2016
  51. Sun Dec 25 00:00:00 GMT 2016
  52.  
  53. Sun Jan 29 00:00:00 GMT 2017
  54. Sun Feb 26 00:00:00 GMT 2017
  55. Sun Mar 26 00:00:00 GMT 2017
  56. Sun Apr 30 00:00:00 BST 2017
  57. Sun May 28 00:00:00 BST 2017
  58. Sun Jun 25 00:00:00 BST 2017
  59. Sun Jul 30 00:00:00 BST 2017
  60. Sun Aug 27 00:00:00 BST 2017
  61. Sun Sep 24 00:00:00 BST 2017
  62. Sun Oct 29 00:00:00 BST 2017
  63. Sun Nov 26 00:00:00 GMT 2017
  64. Sun Dec 31 00:00:00 GMT 2017
  65.  
  66. Sun Dec 25 00:00:00 GMT 2016
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement