Compare timestamp for today

I need to compare the timestamp with the date. I just wanted to compare the date with no bit of time. I need to check if the timestamp is the day before yesterday, that is today - 2.

Could you show me a fragment, please? Thanks.

I read the PHP docs but couldn't find a very clean way to do this. What I found is converting the timestamp to a date with a specific format and comparing it with the date that I get by doing a time delta to get the date until yesterday and convert it to a specific format. Dirty

+4
source share
2 answers

You can do this with the strtotime function.

To do all day, I like to edit the timestamp. These are the designations of the seconds from the era. One day is 86400 seconds, so if you do the following caculation:

$time = $time - ( $time % 86400 ); 

You can convert it back to date using the PHP date function, for example:

 $readableFormat = date( 'dm-Y', $time ); 

There is also a lot of internet in this section.

+5
source

you can use strtotime function

 <?php $time = strtotime("5 june 2010"); $before = strtotime("-1 day",$time); $after = strtotime("+1 day",$time); 
+2
source

Source: https://habr.com/ru/post/1342108/


All Articles