Questions tagged [dateinterval]

Data type used for capturing a interval between two date objects. This is found in PHP, Swift, and likely other languages too.

Data type used for capturing a interval between two date objects. This is found in many languages including PHP and Swift (and likely other languages, too).

For more information, see:

221 questions
2
votes
3 answers

Normalize DateInterval in PHP

The situation/issue I have an issue with DateInterval in PHP. Given the following code $interval = new DateInterval("PT6000S"); echo $interval->h; // 0 echo $interval->i; // 0 echo $interval->s; // 6000 echo $interval->format("%h:%i"); // 0:0 I…
Noah Boegli
  • 750
  • 1
  • 7
  • 24
2
votes
2 answers

PHP Display next delivery date for twice weekly deliveries

I have a website where we show next delivery date, eg for a weekly delivery each Tuesday -- although the actual day that deliveries go out needs to be manually changed sometimes. I need to update it to (eg) Tuesday and Friday deliveries, and I'm…
arvana
  • 23
  • 3
2
votes
2 answers

In PHP, how do I get the accurate (not approximate) total individual number of weeks, months and years between two timestamps?

I can do it for days like this: $d1 = new DateTime('2000-01-01 12:00:00'); $d2 = new DateTime('2020-01-01 12:00:00'); $diff = $d2->diff($d1); echo $diff->days; In other words, it works for days. However, the DateTime/DateInterval class has only a…
2
votes
1 answer

Undocumented Properties for DateInterval Class

When I vardump a DateInterval object, in PHP 7.2.1, I get the following output: object(DateInterval)#4 (16) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(14) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) …
Annapurna
  • 529
  • 1
  • 6
  • 19
2
votes
2 answers

Print positive/negative date_diff

Say I have this: $date1=date_create(date('H:I', strtotime('8:00'))); $date2=date_create(date('H:I', strtotime('18:00'))); $diff1=date_diff($date1,$date2); echo $diff1->format("%h:%I"); which outputs 10:00 (hours), but now i want to compare…
Epistomai
  • 455
  • 1
  • 6
  • 16
2
votes
3 answers

find average interval dates from the date colum in mysql server

This is the date column from where I am trying to get average interval from top to bottom. For example First interval would be different between '2008-03-29' and '2009-04-04' and next interval would be the difference between '2009-04-04' and…
naqib83
  • 128
  • 3
  • 14
2
votes
1 answer

ISO 8601 Define repeating interval on Thanksgiving?

I'm trying to define an interval that repeats every year, starting on the 4th Thursday of November at 13:30z and ending on the same day at 15:00z. Can this be done using ISO 8601?
2
votes
1 answer

DateInterval string Problems

I'm trying to do a math problem using datetime in php. The problem that the string that I'm creating is dynamic. If I add as a static string it runs fine, but If I make the string dynamic it fails. Here's a code example. $now = new…
Eric Evans
  • 640
  • 2
  • 13
  • 31
2
votes
1 answer

PHP: DateInterval every two weeks in X days

I have a start date and end date. I'm trying to get all the Tuesdays and Wednesdays of every two weeks. Example: 2017-05-23 (tu) 2017-05-24 (we) 2017-06-06 (tu) 2017-06-07 (we) ... What I'm trying to do in PHP: $start = new…
Victor
  • 724
  • 3
  • 12
  • 32
2
votes
1 answer

SSRS Expression for current monday and current friday

I have the following expression for a text box on a report in SSRS ="TR1's Sent Between "+Format(dateadd(DateInterval.Day,1-WeekDay(Today), Today), "dd/MM/yyyy") this returns sundays date rather than mondays. does anyone know how to show the…
sql2015
  • 591
  • 3
  • 13
  • 34
2
votes
2 answers

PHP DateTime formatting works but DateInterval formatting not working

I've got a bit of PHP code here that calculates (and echos out) a time duration. I have an if/else that chooses how to calculate the duration. Due to the way i have done the calculations, under one circumstance the duration that is output is a…
2
votes
0 answers

DateInterval: Unknown or bad format

I get several dateTime informations through an API. It's format is like P29DT48M56.941999S for example. I would like to convert it with to a readable sting using DateInterval::format. My snippet looks like $interval = new…
Dong3000
  • 566
  • 2
  • 7
  • 24
2
votes
1 answer

PHP DateTime->sub() wont bubble up to days

If DateTime $serverTime is e.g. 2016-02-03 00:30:00 and i subtract 90 minutes like this $serverTime->sub(new DateInterval("PT1H30M")); the $serverTime is now 2016-02-03 23:00:00. Notice that the date remains February 3rd. While it's exepcted that…
IanDess
  • 657
  • 2
  • 11
  • 26
2
votes
3 answers

Why A - B + B != A with PHP DateTime and DateInterval?

Can someone explain to me why adding and subtracting the same DateInterval from DateTime objects results in different dates? Look at the hours: it goes from 20:00 to 19:00 when I subtract the interval, but when I add the interval it's still…
pgorecki
  • 639
  • 6
  • 8
2
votes
2 answers

Substract a DateInterval from another DateInterval

$date1 = new DateInterval('PT100S'); //100 seconds $date2 = new DateInterval('PT20S'); //20 seconds How to make $date1 - $date2? I've searched on google for hours.
Samuel Auger
  • 252
  • 2
  • 10