Questions about performing arithmetic operations on dates and times.
Questions tagged [date-math]
129 questions
6
votes
4 answers
How to Handle Actual Time with Durations in C#?
What's the preferred approach to compare a complete DateTime instance with an hour, minute, and second which represents an actual time of day, with the ability to operate over those triplets (eg add hours, minutes seconds..)?
My current approach is…

Vinko Vrsalovic
- 330,807
- 53
- 334
- 373
5
votes
5 answers
How to calculate the difference between two days as a formatted string?
Here's what I've got so far:
/**
* Parse a duration between 2 date/times in seconds
* and to convert that duration into a formatted string
*
* @param integer $time_start start time in seconds
* @param integer $time_end end time in seconds
*…

mpen
- 272,448
- 266
- 850
- 1,236
5
votes
1 answer
C# Method to sum hh:mm data ???
I want a method that will sum data that is string in the format hh:mm (time hours and minutes)
0:15 + 0:15 = 0:30

abmv
- 7,042
- 17
- 62
- 100
5
votes
2 answers
Lua Date Manipulation Loop
I'm attempting to run a batch script with two date values that I would like to adjust and then have the script run again. I would like to reference a lua script that will adjust those date values for me. I'm using lua simply because most of the…

MRCLE
- 75
- 4
4
votes
2 answers
Grouping hours by moment of the day
I would need to fetch the most common moment of the day (dawn, morning, evening, night) in a group of records. I'm trying to group the results in the moments using CASE-WHEN, but I'm unable to compare the date and an integer. I try this:
SELECT…

Víctor
- 637
- 2
- 7
- 14
4
votes
2 answers
How can I get all the dates within a week of a certain day using datetime?
I have some measurements that happened on specific days in a dictionary. It looks like
date_dictionary['YYYY-MM-DD'] = measurement.
I want to calculate the variance between the measurements within 7 days from a given date. When I convert the date…

user3600497
- 1,621
- 1
- 18
- 22
4
votes
3 answers
Substracting the n value in date()
I want to implement a Javascript countdown timer that has the month value substracted by 1.
To get the date dynamically via PHP I use this code:
$date = "2014:3:19 00:00:00";
$newDate = date("Y, n, j, H, i", strtotime($date));
Which returns:
2014,…

zoora
- 65
- 2
- 8
4
votes
1 answer
DATE_ADD functionality in Ingres
Many (most? nearly all?) SQL dialects have a way to perform this type of function:
date_add( MyDate, MyInterval )
I've been through all of the docs, but I cannot find this functionality in Ingres. My immediate goal is to get "MyDate plus 3 months".…

mdahlman
- 9,204
- 4
- 44
- 72
4
votes
3 answers
calc the working hours between 2 dates in PHP
I have a function to return the difference between 2 dates, however I need to work out the difference in working hours, assuming Monday to Friday (9am to 5:30pm):
//DATE DIFF FUNCTION
// Set timezone
date_default_timezone_set("GMT");
// Time format…

user1250812
- 75
- 1
- 7
4
votes
2 answers
Is this a bug in PHP's DateTime:diff?
>> $start_dt = new DateTime()
DateTime::__set_state(array(
'date' => '2012-04-11 08:34:01',
'timezone_type' => 3,
'timezone' => 'America/Los_Angeles',
))
>> $end_dt = new DateTime()
DateTime::__set_state(array(
'date' => '2012-04-11…

mpen
- 272,448
- 266
- 850
- 1,236
3
votes
3 answers
Convert days in decimal to years, months, days, hours, minutes and seconds
What I have:
A spreadsheet in which Column C consists of number of days in decimal format.
What I need:
I need Column E to convert the value of Column C to years, months, days, hours, minutes and seconds.
What I've tried:
The following formula works…

Clarus Dignus
- 3,847
- 3
- 31
- 57
3
votes
1 answer
How can I prevent divide-by-zero errors in a Stored Procedure?
I tried to execute my brand-spanking-new Stored Procedure from Server Explorer, I got:
Msg 8134, Level 16, State 1, Procedure duckbilledPlatypi, Line 13
Divide by zero error encountered.
Here is the line implicated (13):
@Week1End Week1End,
...and…

B. Clay Shannon-B. Crow Raven
- 8,547
- 144
- 472
- 862
3
votes
3 answers
php strtotime in seconds and minutes
i use ths method to find the difference between two timestamp and get the number of seconds between those two times, and i refresh the information with jquery like a counter.
$diff = strtotime(date('Y-m-d H:i:s')) - strtotime('2014-06-25…

DouzeBri DouzeBra
- 117
- 1
- 2
- 13
3
votes
4 answers
TIMEDIFF() between records that have one value and the other, not just one
I have a table which records the states of a project:
CREATE TABLE `project_states` (
`id` INT(10) NOT NULL AUTO_INCREMENT,
`state_id` INT(10) NULL DEFAULT NULL,
`project_id` INT(10) NULL DEFAULT NULL,
`created_at` TIMESTAMP NULL…

Damien Pirsy
- 25,319
- 8
- 70
- 77
3
votes
3 answers
PHP find the days until a date
I have to find the number of days until a date in timestamp format (mysql db)
$row['date_exp'] format is '2013-12-16 10:00:00';
$datenow = date("Y-m-d");
$diff = (strtotime($row['date_exp']) - strtotime($datenow))/(86400);
$days = sprintf("%02d",…

Paolo Rossi
- 2,490
- 9
- 43
- 70