Hello!
I set an ACF called pst_date and filled it with '03.05.2015' on a post.
In my template I'm using:
<?php echo get_field('pst_date'); ?>
Output shows 02.05.2015.
Same happens for other years even 2020.
Now I was curious and tried other dates and both input '29.03.2015' and '30.03.2015' have same output of '29.03.2015'.
Before the date '29.03.2015' it shows the correct date.
After '29.03.2015' it is one day short.
Same happens for other dates passed the last sunday of march.
So I assume its some DST bug.
Is there any workaround / fix?
Google was not helpful with that particular problem.
wordpress 5.3.2
php 7.0 / 7.1 / 7.2 / 7.3
Thank you.
Related
I am facing an issue in strtotime() in wordpress, that it is subtracting the hours according to my configured local timezone.
For example i tried strtotime("2021-11-16 00:00:00") on online php compiler it shows...
1637020800
but when i run the same on my wordpress site, var_dump(strtotime("2021-11-16 00:00:00")); it shows:
1637002800
which is wrong it is subtracting 5 hours as i set GMT+5 in my general settings.
I tried current_time('timestamp') but it won't help
Please can anyone help?
i found the problem in wordpress version 5.4.2, so basically in time zone if you select city,country it shows you this problem.
While if you select like GMT +5 etc it will show correct.
So i change Karachi to GMT+5 which make it sorted.
I am trying to add weekdays to a date using the below formula:
$date = strtotime($effdate." +5 weekdays");
$date = date('m/d/Y', $date);
It works fine for other days but not for Friday. It points to the next Sunday rather than Friday. I googled for many solutions, but didn't get a clear idea.
Is there a workaround to fix this bug?
If you're running PHP < 5.5.0 then this is a known bug and was fixed in PHP 5.5
Demo
The bug report does provide an alternative function that will work with versions of PHP that are susceptible to this bug, though it's using DateTime objects rather than unix timestamps
This question already has an answer here:
PHP date() shows tomorrow's date
(1 answer)
Closed 8 years ago.
I have a basic php script
<?php
$today = date("Y-m-d");
echo $today;
?>
Which should output 2014-11-14. However, I am getting output of 2014-11-15 even though my system tray displays 2014-11-14.
I changed the system date back one day (13th) and I got the output I wanted (14th)... Earlier today I had to do a system restore and ran Malwarebytes because I picked up a virus. Could this be the cause of this?
Does anyone know where else I can check my systems time other than the system tray?
date() function uses unix timestamps which always is set to +0:00
So use:
date_default_timezone_set('Europe/Zurich');
When you set your default timezone it will automaticly calculate the offset!
the date() function is returning UTC time and not the time on your local computer
Well,this seems strange. Please bear with me. Someone asked this question in SO. He wants the date of previous Monday. So i suggested
$monday=date(Y-m-d,strtotime('Monday this week'))
The output was perfect in my localhost. It showed 2012-07-30. Another guy commented that the function i mentioned isn't working. It is giving the same date like
$monday=date(Y-m-d,strtotime('Monday'))
i.e., 2012-08-06. And he isn't lying! The online editor which he linked is showing next monday's date. Check this! Why is this happening??
I searched, but couldn't get the reason behind it. Is it because of the older versions of php? Any help will be greatly appreciated. Thank you
Somewhere between 5.2.17 and 5.3.10 the problem was fixed: http://viper-7.com/1PPz5m (look at the paste history).
Digging around in the changelog for the 5.3.0 release I found this:
proper support for "this week", "previous week"/"last week" and "next week" phrases so that they actually mean the week and not a seven day period around the current day.
Sounds like that's probably the answer to me. Basically before 5.3.0 this week etc may give you the wrong answer, because it will look for the day in the 7 days surrounding the current date that is a Monday, whereas in 5.3.0 and later it will be interpreted correctly.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How do I calculate relative time?
I want to format dates on my social web app much like Digg.com and other sites do. There, you see very friendly dates, such as:
just now
3 minutes ago
one hour ago
2 weeks ago
6 months ago
etc
Before I wrap my head around creating such a thing, does anyone know of any ready-to-go script for this where I simply insert a datestamp and a friendly date text is given based on how it related to the current time?
PS: I need this in PHP, but pseudo-code or any other language is fine too.
This is a duplicate of this question. It has a flurry of code samples on how to accomplish this, in addition to the code this very site uses. I glanced at it and there seems to be a PHP implementation posted there too.
In addition to all this, if are you using jQuery you can do this client-side with something like the timeago plugin. It has the advantage of updating the text as time passes so if you load a page and it says "posted 5 minutes ago" and look again 5 minutes later, it says "posted 10 minutes ago"
Thanks all for the answers, and sorry for the duplicate question. I did not find the duplicate when I was looking for it because I did not really know what search terms to use.
Anyways, I have my problem solved thanks to the PHP translation of the code used by stackoverflow. I made one tiny change in calculating the delta:
$delta = strtotime(gmdate("Y-m-d H:i:s", time())) - $time;
Since I am storing my dates in MySQL as timestamp in the GMT format, I have to use the same for calculating the CURRENT time. This makes for a timezone neutral comparison, which is exactly what is needed in my case.
You can also do this in SQL:
Best way to convert DateTime to "n Hours Ago" in SQL