Skip to content

Tag: date

Subtracting days from a future date

It is working as expected. $newdate prints as 1 December 2022 However, if the $tour_date is not the current year, it does not work properly. It is still printing as 1 December 2022. The $newdate prints as 1 December 2022. But it should be 1 December 2023 which is -10 days from 11 December 2023. Any idea, that will work

How to process insane date inputs with php

I have a code in php for processing the personal details of a person. I need code to handle the date input such that when the user inputs a year like 1900 and below then the program outputs That is impossible. I have successfully handled how the program should respond if the date input is in the future. The program

new DateTime is not working properly with the future date

I am trying to calculate the differences between 2 dates. The first date is the reservation date, and the second date is the traveler’s birthdate. Format of the $tour_day is 15 December, 202X It works if the reservation date is the current year. However if the reservation date is 2022 or more, than it cannot calculate correctly because is always

DQL with between – string date – PHP

I am trying to do a sql with between. The date data is entered first as a string. Any help with this question? Answer The string is dd/mm/yyyy At the final you will get date like 2021-09-28 and now we can do a between with actual date 2021-10-01 after this you can see the sentence in DB with dd($query->getSQL()); function

Increment variable date in PHP

I am grabbing the post published date (WordPress) and trying to add 2 days to it to create a post expiry date. But I am throwing the following error: Notice: A non well formed numeric value encountered Here is my code: Can anyone point out my error here please? Answer When using slashes to separate your date parts PHP assume

Separate date to several intervals

I’ve got an array like the following : And another array : I would like to create a new $array3 that removes the intervals from $array2 in $array1 to give the following result : As you can see, in $array3 2 new entries were added to remove the interval used in $array2. I don’t know how can I tackle an

PHP: Trying to insert dates in Database

I want to insert all the dates between a starting and an end date into a table in my database. I already found a code for the two dates and the dates between. The problem now is that the dates are not inserted into my database when running the code. Only 0000-00-00 is displayed in my date table. Also no

PHP UTC String to date

I have a problem. In my code I have the following line: The goal is to get the previous and next hour, so I tried this: But then the I get the following result: Because of my timezone (+1) the RunDateTimeGMT0 gets converted to a date of my timezone. I want the following result: How can I keep the date

PHP, MySQL date calculations

I’m trying to add a number of weeks to date, both will be taken from a database, I successfully fetch both needed but I can’t figure out how to make the calculations. So far I tried with “strtotime” but it gave me some weird results How do I do this the right way? The desired result should be printing the