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
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.
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.
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
I'm still fairly inexperienced with scripting, so my knowledge is limited to working with smarty.
I'm working on building a daily news site, and we are going to have an archive of news articles from every day from the past week. If the day of the week hasn't yet passed, it will show the articles from that day of the week last week. On each day's page, I want a head line that says "News from Monday, June 10th" or whatever the date for the last one of those days of the week was.
As far as I can tell, the $smarty.now function is all relative to today's date, so I can't use that. If there is any way I can do this with smarty, or if someone knows of a PHP script that I can include, that would be greatly appreciated.
This is logic that you would normally put inside your PHP script, not smarty. Try something like this:
empty($_GET['day']) ? $day = date('l') : $day = $_GET['day'];
$date = strtotime("last {$day}");
echo "News from ".date("l, F j", $date);
This script assumes that you pass the day as a GET parameter, for example index.php?day=monday. You can assign what's echo'ed to smarty. strtotime() and date() are both powerful and flexible functions, have a look at their PHP documentation
I'm pulling the most recent listened tracks from last.fm and putting them on my website.
Problem is, the times are retrieved in UTC-0 uts format and appear to be an hour out when comparing them to BST times in order to calculate a fuzzy time stamp ("about 5mins ago", "about an hour ago" etc).
Is there any way solve this so the times always match BST/GMT and adjust when entering and leaving daylight saving time?
Here's a snippet of PHP code i'm using at the moment, which results in the times being an hour out.
$now = time(); // use this so all times are to the same second
$tz = getenv("TZ"); // save local setting so we can reset it later
putenv("TZ=Europe/London");
$trackPlayedAt = date('d M Y H:i:s', $track->date->uts);
date() automatically formats to the local timezone. The timezone depends on the configuration of the PHP server. If everything is set correctly, it should just work.
If you are running PHP 5.3 you have more options. Comment with which version of PHP you are running.