This question already has answers here:
Wrong month (February) - DateTime::createFromFormat [duplicate]
(2 answers)
Closed 5 years ago.
So this appears to only be happening today, but this does not seem right to me. I encountered it converting dates from one representation to another, I was not having this problem on other days.
Interactive shell
php > print_r(DateTime::createFromFormat('n Y','5 2017')->format('YM'));
2017May
php > print_r(DateTime::createFromFormat('n Y','6 2017')->format('YM'));
2017Jul
Am I missing something? My expected output for the second statement is "2017Jun"
This is a duplicate of Wrong month (February) - DateTime::createFromFormat
If you do not give it a day it uses today's date as seed.
Since 31/6/17 does not exist it rolls over to the next month.
Related
This question already has answers here:
Get week number (in the year) from a date PHP
(18 answers)
Closed 2 years ago.
For Example, when I give it 01/01/2020 it should know that it's week 1 or 12/03/2020 it is week 13. All this in a Laravel app.
If it implements DateTimeInterface You can use DateTime::format() method with 'W'. More info and usecases here.
This question already has answers here:
Accessing dates in PHP beyond 2038
(5 answers)
Closed 7 years ago.
I need a date which is 35 years ahead of a date which is user input.
With the following code in php
$DoCndm=date("Y-m-d",strtotime($_POST['DoH'] ." +35 years"));
I found that it works correctly upto 22 years but returns output as 1970-01-01 for 23 and above.. Is it a bug ??
Read this link Year 2038 problem
You can not use unix timstamp above 2038 year
This question already has answers here:
Calculate time elapsed in php - spans over 24 hours
(2 answers)
Closed 9 years ago.
I have been searching for a while now regarding on how to format hours in php that will show 000:00:00 instead of 00:00:00.
I need this to calculate the duration of records with start and end Date with a datetime data type in mysql.
The problem with my current format ('H:m:s') is it only count 24 hours and when the duration goes higher than that, it will show 01:00:00 instead of 25:00:00.
Try TIMEDIFF() function in MySQL
Example:
SELECT TIMEDIFF('2008-12-31 23:59:59.000001',
'2008-12-30 01:01:01.000002');
-> '46:58:57.999999'
This question already has answers here:
Difference between two dates in MySQL
(14 answers)
Closed 9 years ago.
I've searched but could not find the solution for my case.
One date is recorded at MYSQL,
for example it returns: 2013-10-18 15:42:06 (which format is this ?)
So I need to get the current date (including hours, minutes and seconds).
Then, subtract the MYSQL date - CURRENT date.
The result, i'll set as an jQuery countdown.
Thanks!
This should work:
$seconds_remaining = strtotime('2013-10-18 15:42:06') - time();
Although if you happen to know what timezone the MySQL time corresponds to, then you should append that to the argument passed to strtotime(), e.g., '2013-10-18 15:42:06 GMT'
This question already has answers here:
How can I compare two dates in PHP?
(13 answers)
Closed 10 years ago.
I am newbe to php. I have small problem to compare dates in php.
I have 4 dates named date1, date2, start_date and end_date in the format yyyy-mm-dd.
i need the functionality like this:
if((date1>=start_date) && (date2<=end_date)){
}
please help me to solve this.
use strtotime to get the timestamps of your dates - this can be easily compared to each other like you already trying it.
If you have PHP 5.3, this is easily handled by the DateTime and DateDiff classes. If you have not, it is much harder, but look at the 'user contributed' section on DateDiff in the online PHP manual.