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

Calculate number of records per value per month, given a table of id, date, and value where the dates are not always consistent

Ok, so I have two tables. locations: +----+-----------+ | id | name | +----+-----------+ | 1 | Location1 | | 2 | Location2 | | 3 | Location3 | +----+-----------+ location_ratings +----+-------------+-----------+--------+ | id | location_id…
zeke
  • 3,603
  • 2
  • 26
  • 41
0
votes
1 answer

DateInterval - Difference between two times

I have 2 times (DateInterval - php) and I would like to get the difference between them (something like "diff()" function for DateTime). My situation: $task->estimate->format('%H:%I'); // HOURS:MINUTES / DateInterval…
Jax-p
  • 7,225
  • 4
  • 28
  • 58
0
votes
1 answer

How to use date difference as an integer in PHP

I have found various methods to calculate the number of dates between 2 dates by first using date_create() and passing it the dates (without time) and then using ->diff on one of the them and works perfectly fine. However when I attempt to do some…
Lincoln
  • 165
  • 1
  • 12
0
votes
2 answers

Conditional tag with DateInterval

how to use conditional tags using DateInterval with hour for scale in PHP for example i will add text "active" if at 21:00 until 23:00
awnew
  • 3
  • 2
0
votes
0 answers

Symfony: What is the desired way to handle time input greater then 24:00

I try to let the user enter contract hours. For example 40:00 contract hours. Currently I have it working: /** * @ORM\Column(type="string", nullable=true) * @Assert\Regex( * pattern="/[0-9]{2}:[0-5]{1}[0-9]{1}/", * match=true, * …
DelphiLynx
  • 911
  • 1
  • 16
  • 41
0
votes
2 answers

PHP recurring event script crashes when set to December

I have an event entry form that allows you to set an event to recur on a monthly basis on a specified date. Everything works just fine until you set it to stop in December. When you save it, it looks like to loads for a while but then eventually…
arch649
  • 1
  • 5
0
votes
2 answers

PHP datetime diff wrong

I am trying to get a difference between two DateTime objects in PHP and the answer seems to be wrong. As you can see the diff() function gives a time difference of 4 hours and 41 minutes, but the time difference is clearly much closer to 7…
Karl Johan Vallner
  • 3,980
  • 4
  • 35
  • 46
0
votes
4 answers

PHP - Adding and Subtracting Days Weird Bug with DateInterval

I am trying to add and subtract # of days to a date using date_add and date_sub, but I get some weird results. I assume this is an easy answer I am just not versed enough in PHP to know why. Here is my code: $y = new DateTime('2016-05-17'); $z2 =…
Webtron
  • 443
  • 2
  • 6
  • 18
0
votes
0 answers

How do I use a GROUP BY, with a date range (i.e. a month) - MySQL

I am trying to create a query that displays the "total number of bagels sold" for a month and having the name of the bagel displayed next to it. I am also trying to include in the list the bagels that "weren't sold". I have a table called Order I…
Jian Li
  • 43
  • 5
0
votes
2 answers

SQL cross join restricted to dates within 7 days of each other

I would like to do a cross join but only retain pairs of records that are within 7 days of each other. My code below retains pairs with exactly the same date. How can it be modified to allow dates within 7 days? I am using SQL Server 2008. SELECT…
user2964644
  • 189
  • 9
0
votes
1 answer

Adding the difference between two dates to another date in php

I have a series of multiple different dates and I want to change them all by the same number. I only know the new date value of the first of the dates. If I wanted to increase them all by the same value, I thought id just substract the current date…
NMLcygni
  • 61
  • 1
  • 7
0
votes
1 answer

Negative hours value in DateInterval::format()

i need to convert number of seconds to date, and then show time difference as days, hours and seconds. But for some reason after some number of days, in last hour before next full day I get negative hours value. Right now this problem occures if…
Radzikowski
  • 2,377
  • 4
  • 27
  • 39
0
votes
2 answers

Mysql Insert date in a database

I am trying to execute the following query: INSERT INTO table_timesheet (name, datein, dateout) VALUES ('Rupert', 'NOW()', '') WHERE NOT EXISTS ( SELECT name FROM table_listnames WHERE datein='NOW()' ); But this returns an error. Basically I…
0
votes
1 answer

in PHP 5.4 How do I add 2 hours to a UTC date variable (and return UTC formatted for ical)

I have a date variable that I need to simply add 2 hours to. It needs to return UTC date formatted like: 20150921T172345Z . None of the date manipulation examples I've seen are exactly what I need and I'm having a hard time converting what I've…
Marley
  • 61
  • 7
0
votes
2 answers

DateInterval with one month in php array

How can I get month Interval in php using DateInterval. If I chose 05 Aug 2015 as start date and 17 Oct 2015 as end date, then my array output should be divided in 3 arrays: 1st array for 05 Aug 2015 - 31 Aug 2015 2nd array for 01 Sept 2015 - 30…
Nikunj Soni
  • 854
  • 1
  • 5
  • 18