All Questions
7,396 questions
1
vote
1
answer
149
views
created_at (server time) is sometimes earlier than clicked_at (client time) — why?
I’m tracking button clicks on my website and storing both client-side click time and server-side insert time in my database.
Frontend (JavaScript)
I capture the click timestamp like this:
clicked_at: ...
1
vote
1
answer
120
views
Floor PHP date/time to top of hour [duplicate]
I want to be able to floor a time to the top of the hour, e.g. 14:50:35, becomes 14:00:00.
Either unix timestamp or DateTime/DateTimeImmutable, etc. is OK, but I cannot figure out how to do it. I ...
2
votes
1
answer
56
views
Split CarbonPeriod into days (PHP)
I have this CarbonPeriod with start 2025-06-09 19:00 and end 2025-06-11 11:00. What I want is an array of the days with start and end date. So basicly an array like this, possibly with new ...
1
vote
2
answers
62
views
DateTimeImmutable yielding distinct timestamps in distinct PHP runtimes
Running the following script:
var_dump(
(DateTimeImmutable::createFromFormat(
format : 'Y-m-d H:i:s',
datetime: '2120-10-03 07:00:00',
timezone: new DateTimeZone('Europe/...
2
votes
2
answers
130
views
PHP new DateTime() with unix timestamp ignores Timezone for application and also explicit Timezone in constructor
I have an object which have created property like unix timestamp integer.
I try to convert this property to DateTime object and supposed the PHP will set up correct Timezone according application ...
0
votes
1
answer
56
views
WP Query to identify future dated Woocommerce products with custom meta date field
I am trying to search for future dated Woocommerce products, but the query is not working. As it happens, the _custom_date field values are stored in UK date format e.g. 24/01/2025. Any ideas?
$args = ...
1
vote
2
answers
316
views
PHP Carbon diffInWeekdays alternative to return float instead of int
I'm working on a leave/holiday management system.
As well as booking full days leave/holiday they can book half days (morning or afternoon off).
I need to calculate the total amount of days during a ...
0
votes
1
answer
51
views
How better reformat a date using PHP [duplicate]
We have code line:
$result = "{$list[ 'ga_event_start_date' ]} - {$list[ 'ga_event_end_date' ]}";
And the dates display as 'd M y'
We need to remove the 'y' numeral.
Can this be done in ...
-1
votes
1
answer
82
views
PHP MYQSL single insert statement to enter either NULL, or time as datetime value when INSERT statement uses variable? [duplicate]
Apologies up front: Self taught so sometimes I miss something really basic...
I have a JS application where users can enter a time in a form and can revisit the form and edit the time later. The entry ...
0
votes
1
answer
124
views
How to subtract/add years/month intervals to a date (like MySQL INTERVAL expression)
Let's say I need to change a datetime object by adding or subtracting some months.
How to avoid the well known PHP month calculations?
$monthstoadd=-1;
//today is 2025-01-24
$date=new DateTime("...
0
votes
2
answers
94
views
Why does uppercase Y shows the next year for the dates close to the year end when using IntlDateFormatter?
At the end of each month i want to write down the month in serbian latin alphabeth format to write down the month in letters and the full year.
Example:
Januar 2024
Februar 2024
...
Decembar 2024
etc....
1
vote
1
answer
76
views
Wrong Time Returned For Greenland & Kazakhstan [duplicate]
date_default_timezone_set() & date() functions return correct date & time for all countries except for Greenland & Kazakhstan.
The following returns 1 hour behind of the correct time in ...
0
votes
1
answer
54
views
Adding time with strtotime give incorrect results when going past midnight [closed]
I recently noticed that if I run the following command:
echo date("Y-m-d h:i:s", strtotime("2024-11-26 23:30:00 +3600 seconds"));
The result is 2024-11-27 12:30:00 which is ...
3
votes
1
answer
454
views
Why does Carbon::createFromFormat() not throw an exception when given a UK format and a US date?
I have this code:
try {
Carbon::createFromFormat('dmY', $rawDate)->format('Ymd');
} catch (InvalidFormatException $e) {
echo 'Oops, bad date format.';
}
If I feed in 31012024 as my $...
1
vote
2
answers
723
views
How to get WooCommerce orders created from a given start date?
I need to get orders only if order was created from given date, let's say: 01/11/2024.
Then I would get order created from the day 01/11/2024 to the actual date (today).
I found this code which does ...