How to display anything in php in between particular time duration?

后端 未结 7 1891
离开以前
离开以前 2021-01-18 22:05

I have a php code as shown below in which I want to display anything in between two calendar days of the week.

The values coming inside $data->{\"select_s

7条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-18 22:21

    I would keep all the dates in the same format. Unix time is a great way to store the time because you can easily run calculations.

    In your example you are calculating using both strings and numbers. In fact you have 3 different ways of expressing the date. I suggest using just date() to save and compare all of the values and only format that Unix timestamp when displaying to the end user.

    ↓↓↓↓ new edit ↓↓↓

    Look carefully at what your code is returning:

    $arradate = strtolower(date('D')); //echos the day ex: sun
    $nowtime = (int)date('His'); //echos a different format ex: 25019
    

    And have a good read of the date function's docs, specifically the arguments you chose for nowtime which are 'His' which will return:

    H 24-hour format of an hour with leading zeros 00 through 23

    i Minutes with leading zeros 00 to 59

    s Seconds with leading zeros 00 through 59

    Now consider that date() returns a Unix timestamp and you will see the failure. You simply need to remove the formatting of the date in all the code save for elements that display to the end user. The computer gets no benefit from knowing it is Wednesday. The computer only counts up from the year 1970.

    So you just need one argument to call the current date. Either will work:

    $arradate = date(); 
    $nowtime = date(); 
    

    Finally after reading about Unix time you will see that the dates you have stored are backwards. You end_time is day 0 and your start time is two days after that.

提交回复
热议问题