Questions tagged [date-arithmetic]

The term 'date-arithmetic' refers to determining via code such information as how many days, hours, etc. between two calendar dates, and determining the last day of the month, or whether a date is a weekday or a weekend. Be sure to also include the appropriate programming or database tag.

Many computer languages provide for date arithmetic, including , , and languages. Most languages store data with a type of date internally as a number of days since a certain date, such as January 1st 1970 for Unix.

Typical Considerations

  • Basic calculations such as number of days between two dates, number of months between two dates, etc.
  • Scheduling problems often involve how to determine the fifth business day of the month, the last day of the month, the fourth Thursday of the month
  • Regional or Client-specific concerns include whether certain days are holidays, etc.
  • Week number of the year (ISO: Monday as first day of week, Unix: Sunday as first day of week)
1101 questions
7
votes
4 answers

Subtracting n Days from a date using SQL

I am quite a beginner when it comes to Oracle. I am having trouble figuring out how to do something similar to this : SELECT ID, NAME, TO_CHAR(DATEBIRTH, 'DD/MM/YYYY HH24:MI:SS') FROM PEOPLE WHERE DATEBIRTH >= ANOTHERDATE - NDAY To put it short, I…
MrMokari
  • 125
  • 1
  • 1
  • 7
7
votes
5 answers

Simple Java Date Calculations

I would like to do simple date calculations in Java. For example, compute the difference in days between to dates (having a 0 time component). Of course you could do a simple substraction of milliseconds, divided by the number of milliseconds per…
mikemax
  • 73
  • 1
  • 1
  • 4
7
votes
4 answers

oracle query between two dates with hours

This is my current oracle table: DATE = date HOUR = number RUN_DURATION = number I need a query to get RUN_DURATION between two dates with hours like Select * from Datatable where DATE BETWEEN to_date('myStartDate', 'dd/mm/yyyy hh24:mi:ss') +…
Kᴀτᴢ
  • 2,146
  • 6
  • 29
  • 57
7
votes
5 answers

What is the correct end-of-day interpretation?

Over the years I have come across different interpretations of the end of a day. But what is the correct way of representing it when comparing dates and intervals? I have found that some people seem to prefer 23:59:59, while others do use…
user122830
7
votes
3 answers

Summarize values across timeline in SQL

The Problem I have a PostgreSQL database on which I am trying to summarize the revenue of a cash register over time. The cash register can either have status ACTIVE or INACTIVE, but I only want to summarize the earnings created when it was ACTIVE…
7
votes
1 answer

Trying to subtract 5 days from a defined date - Google App Script

I'm trying to write a script which is supposed to send out an email and create two calender entries when submitting a form. To be honest, this is my first script and I am very happy that the email is send out and the calender entries are working as…
user3006481
  • 87
  • 1
  • 2
  • 6
7
votes
2 answers

Find the NSDate for next Monday

I want to get the date of the next Monday after the current date. So if today's date is 2013-08-09 (Friday) then I want to get the date 2013-08-12. How can I do this?
ChandreshKanetiya
  • 2,414
  • 5
  • 27
  • 41
6
votes
3 answers

How to truncate a date to the first day of the month in Snowflake?

I am not able to find any good conversion code to get 2014-02-17 into 2014-02-01 without having to use concatenation and a ton of formatting. I wonder if someone can help me find a good command to achieve this. Thanks!
ee8291
  • 495
  • 4
  • 9
  • 18
6
votes
3 answers

Split up datetime interval according to labeled partition of a week

I have shift which is a datetime interval (a pair of datetimes). My weeks have a labeled partition (every week is the same: divided into parts, and each part has a label). I want to split up shift into labeled parts (i.e. into several subintervals),…
Ricardo Buring
  • 213
  • 2
  • 14
6
votes
3 answers

Pandas: Get per-year counts for Dateranges spanning multiple years

I have a dataframe with records spanning multiple years: WarName | StartDate | EndDate --------------------------------------------- 'fakewar1' 01-01-1990 02-02-1995 'examplewar' 05-01-1990 03-07-1998 (...) …
Jasper
  • 2,131
  • 6
  • 29
  • 61
6
votes
2 answers

Calculate Difference between dates by group in R

I'm using a logistic exposure to calculate hatching success for bird nests. My data set is quite extensive and I have ~2,000 nests, each with a unique ID ("ClutchID). I need to calculate the number of days a given nest was exposed ("Exposure"), or…
birdnerd
  • 83
  • 1
  • 1
  • 5
6
votes
3 answers

ISO week number in CMD

How can I determine the (ISO 8601) week number in a Windows batch file? Unfortunately WMIC PATH WIN32_LOCALTIME GET /FORMAT:LIST only has WeekInMonth... I have found some very complex solutions. Is there no easier way?
Michel de Ruiter
  • 7,131
  • 5
  • 49
  • 74
6
votes
2 answers

SQL date conversion results to "invalid number format model parameter."

I have to select some data from Oracle 11g database, but I can't seem to figure out why following select query is failing: SELECT INFO_ID, INFO_DETAIL, IMPORTANT_FLG, DELETE_FLG, CREATE_TIME, DISPLAY_ORDER FROM TABLE_NAME WHERE…
julumme
  • 2,326
  • 2
  • 25
  • 38
6
votes
4 answers

How to get age in years,months and days using Oracle

I'm trying to print for each person its age using this format : E.g : 19 years , 8 months , 13 days. I've googled a lot and I've noticed that there is a specific function to calculate the difference between dates DATEDIFF. However this function does…
mariuss
  • 1,177
  • 2
  • 14
  • 30
6
votes
4 answers

Date/Time Difference in Oracle for same field in different rows

I have the below view, what I need to do is to get the date difference of the field ActionDate between each 2 records having the same Vehicle AND OrderCode, how can I achieve this in Oracle database. Also taking into consideration that the dates…
Alex
  • 5,971
  • 11
  • 42
  • 80