Posts

How to add hours in date time in PHP?

< 1 min readTo add hours to a datetime in PHP, you can use the DateTime class along with the DateInterval class. Here’s an example code snippet: In this example, we’re starting with a datetime of ‘2023-02-25 10:30:00’ and adding 2 hours to it. The DateTime object is created using the initial datetime string. The add() method is…

Read More

How to add minutes to time in PHP?

< 1 min readTo add minutes to a time in PHP, you can use the date() function along with the strtotime() function. Here’s an example code snippet: In this example, we’re starting with a time of ’10:30:00′ and adding 15 minutes to it. The strtotime() function takes a string argument, which in this case is “$time + $minutes_to_add…

Read More

How to get yesterday’s date in PHP?

< 1 min readYou can use the PHP date() function along with strtotime() to get yesterday’s date in PHP. Here’s an example code snippet: In this example, we’re using the “Y-m-d” format for the date, which outputs the date in the format of “YYYY-MM-DD”. The strtotime() function takes a string argument, which in this case is “-1 day”,…

Read More

How to get tomorrow’s date in PHP?

< 1 min readIn PHP, you can get tomorrow’s date using the date() function along with the strtotime() function. Here’s an example: In this example, we use the strtotime() function to add one day to the current date, and then pass the resulting timestamp to the date() function to format it in the desired YYYY-MM-DD format. If you…

Read More

How to get the next month from date in PHP?

< 1 min readIn PHP, you can get the next month from a date using the date() function with the “m” and “Y” format characters. Here’s an example: In this example, we first convert the date string to a Unix timestamp using the strtotime() function. We then use the date() function with the “Y-m” format characters to output…

Read More

How to check if a date is in the future in PHP?

< 1 min readIn PHP, you can check if a date is in the future by comparing it to the current date and time using the time() and strtotime() functions. Here’s an example: In this example, we first convert the date string to a Unix timestamp using the strtotime() function. We then get the current Unix timestamp using…

Read More

How to check if a date is in past in PHP?

< 1 min readIn PHP, you can check if a date is in the past by comparing it to the current date and time using the time() and strtotime() functions. Here’s an example: In this example, we first convert the date string to a Unix timestamp using the strtotime() function. We then get the current Unix timestamp using…

Read More