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
1
vote
1 answer

Proper way to save a DateInterval to Realm

Realm doesn't support DateInterval to be store into the database. For now our team do the following: private let _intervalBegins = List() private let _intervalEnds = List() var dateIntervals: [DateInterval] { get { var…
SquareBox
  • 823
  • 1
  • 10
  • 22
1
vote
0 answers

Echo date interval in a PHP calendar

I am creating a calendar and I am in a dire need of a solution. There are records of information in the database and the code reads these records. Two columns hold a date from and a date to. I have to output these dates that appear in the database…
kaspianso
  • 43
  • 7
1
vote
1 answer

php - how to include time slot breaks using DateTime

I want to create time slots with start, end time & also break start and end. I have achieved to generate the time slots but without the break between 11:10 - 11:25 LIVE CODE EXAMPLE Input variables $duration = 35; // how much the is the duration of…
cipriano
  • 111
  • 2
  • 11
1
vote
2 answers

PHP adding two DateInterval-objects together

I'm crunching some numbers from a time recording experiment using PHP. How do I add two DateInterval-objects together? One of the DateIntervals are found as such (the difference between two DateTime-objects): $start_stamp = new \DateTime(…
Zeth
  • 2,273
  • 4
  • 43
  • 91
1
vote
1 answer

Increment DateInterval within loop

I have a mySQL table with 2 columns that contain a date. The while loop puts each of them into a variable: $start_date and $end_date, calculates the time between them and puts that into a new variable $since_start by using diff(); As far as I've…
Wu Wei
  • 1,827
  • 1
  • 15
  • 27
1
vote
1 answer

mysqli query date interval

I have an event in my mysqli database with is due to reoccur every year, i have set up a query which will create a new event exactly 1 year after the present event finishes. I am wondering if i can set the new date not to be exactly 1 year from the…
BBLJ84
  • 175
  • 1
  • 12
1
vote
0 answers

PHP DateInterval comparison bug?

OK I think I have found a pretty strange bug. I have 2 objects of the type DateInterval and is trying to evaluate if one is bigger than the other - however this fails unless I do a var_dump() on both objects first! 1st example //** THIS WORKS AND…
Ulrik Pedersen
  • 73
  • 1
  • 12
1
vote
0 answers

PHP DateTime diff creates DateInterval with negative hours

I recently discovered a strange behavior of DateTime diff(). I just tried to calculate the difference between the following dates: $first = new DateTime('2016-07-05T00:00:00'); $second = new DateTime('2016-12-30T23:59:59'); $interval =…
Dom
  • 11
  • 2
1
vote
0 answers

DateInterval Object - "d" and "days"

I have the following function: format('Y')*360 +…
J. Andrew
  • 11
  • 1
1
vote
1 answer

Carbon: compare diffForHumans

I'm using Laravel 5.3 and Carbon library. I'm trying to compare multiple diffForHumans results. For example I have three differences: 3 weeks after 7 days after 2 days after Is it possible to compare these to find minimum, maximum and average…
dbr
  • 1,037
  • 14
  • 34
1
vote
2 answers

PHP DateInterval

I have this function witch return an array of date. I need to jump on every seven days from now until last year. $date[] = $lastDate = (new \DateTIme('NOW'))->format('Y-m-d'); for ($i = 1; $i < 54; ++$i) { // 54 -> number of weeks in a year …
Kevin
  • 4,823
  • 6
  • 36
  • 70
1
vote
2 answers

PHP DateTime sub produces unexpected results

I have the following example of me subtracting the DateInterval from DateTimeImmutable $dateA = new DateTimeImmutable('2016-06-30'); $dateB = new DateTimeImmutable('2016-05-31'); $dateInterval = new DateInterval('P3M'); // print…
Jan Tajovsky
  • 1,162
  • 2
  • 13
  • 34
1
vote
1 answer

SQL request with date comparison

I have a trouble concerning my request, and my date column. Here is my table event: id (int, pk, ai) date (datetime) location (char) link (char) I would like to display 6 events on my page. The 3 last, and the next 3, compared to today's date. But…
1
vote
2 answers

Add Date Interval to Date Time

I have 2 Datetime Objects and I used diff to get an interval. I then want to add this interval to another date to get a date in the future. Here is my code: $start = new DateTime($start_date); $stop = new DateTime($end_date); $interval =…
Severian
  • 427
  • 3
  • 18
1
vote
3 answers

PHP Fatal error when trying to add a DateInterval to a DateTime object

What am I doing wrong here? PHP Fatal error: Call to a member function add() on a non-object in $rndM = rand(48,51); $rndS = rand(1,59); $ts = new DateTime($krow['GLSTRT']); $tsd = $ts->format('Y-m-d H:i:s'); $tsup =…
dft99
  • 69
  • 8