Questions about performing arithmetic operations on dates and times.
Questions tagged [date-math]
129 questions
3
votes
1 answer
Rails 3 Calculate age of embedded records
I'm using mongodb, and have a model that adds comments as embedded documents.
How do I get the average age of comments for an entry? (relative example, my fields vary a little)
So I can have many comments for an entry, and I need to find out the…

Kevin Brown
- 12,602
- 34
- 95
- 155
3
votes
2 answers
Making NSTimeZone Trouble Free in Unit Tests
So here's the problem with doing unit tests of calendar code in Objective-C: the Timezone contains the information about daylight savings, so you write a test in the summer, expecting sunrise on June 10th to occur at 6:02 am. Your test passes,…

Rob
- 11,446
- 7
- 39
- 57
2
votes
1 answer
Subtract months from a given date
I need to subtract months from a given DateCol in a matrix. I was using the command bsxfun(@minus, datevec(date),[0,3,0,0,0,0]) to subtract 3 months from the given date. You can see there is a bug in this code. If the date is 1-Feb-2011, this…

Maddy
- 2,520
- 14
- 44
- 64
2
votes
1 answer
Calculating number of Quarters between 2 dates in DAX, applying filter
I have the following table, tbl_Episodes (10K records):
ClientID AdmDate DischDate
54 9/20/2013 5/28/2015
63 3/07/2013 4/12/2014
75 4/07/2014 12/31/2050
. …

Hell-1931
- 489
- 1
- 6
- 24
2
votes
1 answer
Find the nearest overlap between given time series
I'm building a scheduling system where I store an initial appointment and how often it repeats. My table looks something like this:
CREATE TABLE (
id serial primary key,
initial_timestamp timestamp not null,
recurring interval
);
id …

Jaden Baptista
- 656
- 5
- 16
2
votes
1 answer
Round-trip conversion of a System.DateTime instance via a Unix time stamp is off by 1 hour
Note: For convenience, PowerShell is used to demonstrate the behavior, but the question is about surprising behavior of the System.DateTime .NET type, contrasted with type System.DateTimeOffset.
There may be a good conceptual reason for this…

mklement0
- 382,024
- 64
- 607
- 775
2
votes
1 answer
please explain my error in this javascript date math
Here's the output from the Visual Studio Immediate Window. I start with mondaysDate, create a second date, thisDate, and then add integers to it using mondaysDate as the base.
I don't understand why adding 3 to the date yields November 2 and adding…

Tim
- 8,669
- 31
- 105
- 183
2
votes
6 answers
Comparing SQL date without current month
I have a table in Access with string columns and a date column. I want to get all the rows from the table when the date is lower than 22.10.2010, except this month. So, i need the rows from 30.09.2010 to ...
I tied something, but I figured out it's…

DaJackal
- 2,085
- 4
- 32
- 48
2
votes
1 answer
Oracle downtime in minutes per month
This is written in Oracle 11g or 12c...
Hello,
I am attempting to shape this data into hours of downtime for the previous 12 months, shaped this way to support a graph.
In the Oracle SQL query below, the commented query "M" shows how to put in one…

SMerrill8
- 528
- 4
- 12
2
votes
3 answers
PHP strtotime Issue with date differences
Anyone can explain me what is wrong with strtotime function in this example? I'm trying to count differences between dates. PHP 5.6.0 (cli) (built: Aug 28 2014 08:03:51)
When i execute this loop it displays number 88…

MEAT
- 49
- 6
2
votes
2 answers
Best practice for PHP/MySQL Appointment/Booking system
I need some people to battle a "best practice" for a PHP/MySQL appointment system for a hairdresser I'm currently working on. Hopefully, together we can clear some things up to avoid having to re-do the system afterwards. I've been looking at SO and…

Joshua - Pendo
- 4,331
- 6
- 37
- 51
2
votes
3 answers
Find only particular days between two dates
I have an Oracle table with data like below:
1. ID DATE
2. 12 02/11/2013
3. 12 02/12/2013
4. 13 02/11/2013
5. 13 02/12/2013
6. 13 02/13/2013
7. 13 02/14/2013
8. 14 …

user2089954
- 61
- 2
1
vote
3 answers
Date manipulation in PHP
I am trying to repeat the date by a month for a fixed number of times in a loop. It will only echo the date if the date is a valid date otherwise it will skip the date.
For example if the "2012-02-30 10:10:00" is coming in the loop it will be…

Nihilarian
- 1,190
- 1
- 10
- 17
1
vote
1 answer
PHP Date Subtract Only works first iteration of Do While Loop
I have mySQL tables that are suffixed with 'mmdd'. I need to iterate through and store this 'mmdd' value in an array as I get a hit on the table. The problem is that the date subtract of 1 day only works on the 1st iteration. I have tried this many…

user1341613
- 23
- 4
1
vote
2 answers
How can i parse a date to same day of previous month?
How can i parse a date to same day of previous month in PHP?
Example:
input Output
2018-07-25 -> 2018-06-25
2018-07-31 -> 2018-06-30 (because there is no 31)
My code
$d = "2018-07-25";
$xd =…

Rafeeq Mohamed
- 182
- 1
- 4
- 14