Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a check if this timestamp is today,tomorrow or the day after tomorrow?

Tags:

date

php

I would like to know how to check if the timestamp is today, tomorrow or the day after tomorrow.

I have e.g. :

$timestamp = "1313000474";

How to make a check if this timestamp is today,tomorrow or the day after tomorrow?

e.g.

if today then echo $output = "today";
if tomorrow then echo $output = "tomorrow";
if the day after tomorrow then echo $output = "dayaftertomorrow";

How to do this?

EDIT: corrected unix timestamp

Thank you in advance.

like image 369
qwentinnau Avatar asked Aug 10 '11 17:08

qwentinnau


People also ask

How do you check the date is today or not in PHP?

Answer: Use the PHP date() Function You can simply use the PHP date() function to get the current data and time in various format, for example, date('d-m-y h:i:s') , date('d/m/y H:i:s') , and so on.

How do you add 2 hours to a timestamp?

To add 2 hours to the Date Object first, we get the current time by using the Date. getTime() method and then add 2 hour's milliseconds value (2 * 60 * 60 * 1000) to it and pass the added value to the Date Object.

How can I get tomorrow date in PHP?

$newDate = date('Y-m-d', strtotime('tomorrow')); echo $newDate; ?>


1 Answers

$timestamp = "1313000474";

$date = date('Y-m-d', $timestamp);
$today = date('Y-m-d');
$tomorrow = date('Y-m-d', strtotime('tomorrow')); 
$day_after_tomorrow = date('Y-m-d', strtotime('tomorrow + 1 day'));

if ($date == $today) {
  echo "today";
} else if ($date == $tomorrow) {
  echo "tomorrow";
} else if ($date == $day_after_tomorrow) {
  echo "dayaftertomorrow";
}
like image 200
Dan Grossman Avatar answered Oct 22 '22 00:10

Dan Grossman