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
3
votes
1 answer

PHP DateInterval create split second (microsecond or milisecond) interval

How to create split second DateInterval in PHP? For example: 0.123456 sec ? interval_spec of DateInterval::__construct does not have F nor f similarly to DateInterval::format that supports split seconds. Relative format listing of…
Jimmix
  • 5,644
  • 6
  • 44
  • 71
3
votes
4 answers

Postgresql generate date series (performance)

Using postgresql version > 10, I have come to an issue when generating date series using the built-in generate_series function. In essence, it does not accord for the day of the month correctly. I have many different frequencies (provided by the…
chvndb
  • 615
  • 8
  • 18
3
votes
1 answer

Decreasing DateInterval not producing result

Trying to get the last four Sundays, decrementing in a loop starting with the most recent Sunday first. // most recent sunday $mostRecentSunday = new DateTime('last sunday'); // four Sundays ago $maxDateAttempt = clone…
Talk Nerdy To Me
  • 626
  • 5
  • 21
3
votes
1 answer

Convert eBay timeLeft to Swift 3.0 TimeInterval

I am trying to convert the eBay timeLeft to a TimeInterval. The timeLeft value is returned from eBay as. Apparently the value is ISO 8601 (see link and question below). I believe the timeLeft is an interval relative to when I made the API…
Jacksonsox
  • 1,114
  • 15
  • 25
3
votes
4 answers

How to retrieve the number of days from a PHP date interval?

I am trying to retrieve the number of days for a PHP interval. When I run the following piece of code on http://sandbox.onlinephpfunctions.com/: $duration = new \DateInterval('P1Y'); echo $duration->format('%a'); echo "Done"; I…
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
3
votes
0 answers

Definition of DateInterval's given period's roll-over-point

From DateInterval's official documentation, it mentions that: The specification can also be represented as a date time. A sample of one year and four days would be P0001-00-04T00:00:00. But the values in this format can not exceed a given period's…
Raptor
  • 53,206
  • 45
  • 230
  • 366
3
votes
5 answers

How to get the difference in months between two dates in PHP

I wanted to calculate the difference between two dates in month with PHP but it seems like there is a bug somewhere. $datetime1 = new DateTime(date('Y-m-d')); $datetime2 = new…
mlwacosmos
  • 4,391
  • 16
  • 66
  • 114
3
votes
2 answers

PHP DateInterval format minutes and seconds with leading zero

Trying to generate simple "H:i:s" string from seconds, but can't example: $iSecond = 188; $dtF = new DateTime("@0"); $dtT = new DateTime("@$iSecond"); $size = $dtF->diff($dtT)->format('%H:%i:%s'); echo $size; should show "00:03:08" , but in fact…
3
votes
2 answers

How calculate the difference of time (+/-) between each row?

I'm echoing my MYSQL database using PHP and trying to calculate the difference of "time" in each row for the column "time". I have "time" stored in TIME format HH:MM:SS (00:00:00) in the MYSQL database. Example of the output I'm trying to…
michelle
  • 623
  • 2
  • 6
  • 22
3
votes
1 answer

Ebay API ISO 8601 duration format to timestamp

Ebay API provides me time in ISO 8601. For example, it gives me item time left: P0DT0H1M4S Here is how this time is formatted: ebay duration I want to convert this time to simple Y-m-d H:i:s format. So far I've tried date("Y-m-d",…
casper123
  • 1,736
  • 4
  • 21
  • 39
3
votes
1 answer

How to set a DateInterval in php?

I've got this function which creates sets an expiration for something. The function takes a couple arguments which have default values. I do this like so: public static function blockAccount( $id, $years = 0, $months = 0, $days = 0, …
kramer65
  • 50,427
  • 120
  • 308
  • 488
3
votes
1 answer

Calculate months between two dates using DateInterval without wrapping within a year

I am aware this topic is pretty exhausted, but obviously not quite enough! $temp_d1 = new DateTime(date('Y-m-d', $fromTime)); // 2012-01-01 $temp_d2 = new DateTime(date('Y-m-d', $endTime)); // 2013-02-01 $interval = $temp_d2->diff($temp_d1);…
Jamie Edwards
  • 755
  • 6
  • 15
2
votes
1 answer

PHP: Weird DateInterval length calculation

While playing with PHP, I strucked on this :
Clement Herreman
  • 10,274
  • 4
  • 35
  • 57
2
votes
2 answers

DateIntervalFormatter: string of format "m:ss"

I'd like to get a string of format "m:ss" out of two dates. E.g.: "0:27" for 27 seconds difference and "1:30" for 90 seconds difference between dates. Here's the code I'm using: import Foundation let formatter =…
Richard Topchii
  • 7,075
  • 8
  • 48
  • 115
2
votes
1 answer

Start date/end date for biweekly payroll frequency - Swift

I have to present time trackings summary for specific payroll frequency periods: monthly, weekly, biweekly. I did find a way to get start date and end date for current week or current month ex. var startOfMonth: Date? { let components =…
vandermesis
  • 63
  • 1
  • 8
1 2
3
14 15