how to get date for holidays using php

前端 未结 5 577
后悔当初
后悔当初 2020-12-14 08:38

For example the:

  1. 3rd Monday of January for Martin Luther King Day
  2. 3rd Monday of February for Presidents
5条回答
  •  旧巷少年郎
    2020-12-14 09:06

    You can leverage this function of php. strtotime

    $currentYear = date("Y");
    

    MLK Day -

    echo date('Y-m-d', strtotime("third monday of january $currentYear"));
    

    Presidents Day -

    echo date('Y-m-d', strtotime("third monday/OD February $currentYear"));
    

    Easter -

    echo date('Y-m-d', strtotime("last sunday of march $currentYear"));
    

    Memorial Day -

    echo date('Y-m-d', strtotime("last monday of may $currentYear"));
    

提交回复
热议问题