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

Return date 7 days passed target date | SQL

I am trying to get all tickets that are still open passed a specified 'closure' date by 7 days and the 'bill date' is passed 7 days. Tickets look like: Work Order: Description: Status: Task: End Date: Billed…
ZebulaCodes
  • 13
  • 1
  • 6
-2
votes
2 answers

Date Interval SQL

I have a database that contains Freight Data. I am trying to get the three ship countries with the highest average freight charges. I want to use only the last 12 months of order data, using as the end date the last Order Date in the Orders table.…
-2
votes
3 answers

MySQL convert timestamp and time string to DateTime format

In my table have two columns, one as timestamp to save the date and one as time string to save the time with period. Eg: I want to combine them into one column as DateTime format in the result then order by desc on that column. Here is the…
dangquang1020
  • 496
  • 3
  • 7
  • 23
-2
votes
1 answer

Generate month data series with null months included?

I have a simple calendar year monthly data set returned but I know I will have missing months (i.e. no data). I found this answer here: Best way to count records by arbitrary time intervals in Rails+Postgres It's close but I do not understand the…
Dan Tappin
  • 2,692
  • 3
  • 37
  • 77
-2
votes
1 answer

Convert String Date to Unix TimeStamp Sqlite3

I've to copy a column in another column, but the result is that only the first row is copied and put in all the rows of the other column I'm trying to execute this query: UPDATE gdf_storico Set Data = (SELECT Giorno FROM timestamp) But that stores…
-2
votes
1 answer

Sql query to get row from date filled

I want to get data from training_course table where current date minus 5 days is equal to training_end_date. Training_end_date is my field in the table. Thanks
-2
votes
2 answers

how can i check if value exists before the date specified in sql server

I have the data below in a sql table, ID | supplier | Supplier_Due | Date | 1 | S-0003 | 14850 |2020-11-09 2 | S-0003 | 850 |2020-11-09 3 | S-0003 | 21750 |2020-11-13 4 | S-0003 | 975 |2020-11-15 5 |…
Temitayo
  • 39
  • 8
-2
votes
3 answers

Alter table and set default as current date

while creating a table I forgot to add a date of birth column. Is there a way to add a NOT NULL column to a table with default value being current date?
joel
  • 263
  • 1
  • 5
  • 16
-2
votes
2 answers

Convert date to PostgreSQL syntax

The following logic in SQL Server needs to be converted appropriately to PostgreSQL syntax. Please helpm me convert this over to the correct syntax so I can use it in PostgreSQL database: convert(DATE, dateadd(m, -17, convert(DATE, getdate())))
an1234
  • 165
  • 1
  • 12
-2
votes
5 answers

How do I subtract two datetime values?

I have a table with two columns login and logout. If a row has values "2019-08-07 20:37:12" in login column and "2019-08-07 21:14:16" in logout column, I want the difference between time values from login and logout columns. I have: SELECT…
-2
votes
1 answer

Converting TRUNC(TO_NUMBER(TO_DATE(SYSDATE) - MyTable.DOBDATE) / 365, 0) from Oracle to SQL Server?

I am converting Oracle queries to a SQL Server equivalent, some have been easier than others, right now I am stuck on a query that is containing this in a where clause TRUNC(TO_NUMBER(TO_DATE(SYSDATE) - MyTable.DOBDATE) / 365, 0) I've read that…
Chris
  • 2,953
  • 10
  • 48
  • 118
-2
votes
3 answers

LAG Function in Oracle

I have a table (incident) that has column Create_date(DataType=Date). I want to get difference in Days OR Hours from Previous Record. Like the screenshot below. From Second Record Create_Date I want to minus First Create_Date and from Third Create…
Shilpi
  • 25
  • 2
  • 12
-2
votes
3 answers

Logical Error - convert Fah to Celsius

#include #define F(x) 32 + (x*9)/5 int main(void) { int F,C; printf ("Enter temperature in celsius="); scanf ("%d",&C); F(C); printf (" %d fahrenheit = %d celsius\n", F, C); return 0; } When I input 10 celsius, it comes…
belle
  • 23
  • 4
-2
votes
1 answer

Subtracting Dates using Java Calendar

I have 2 Calendar objects for the current date and birthdate. I need to subtract birthdate from the current date and return the difference in years (a truncated Int is all I need). What's the simplest way of doing this?
M-R
  • 411
  • 2
  • 6
  • 15
-2
votes
1 answer

oracle sql developer dealing with months

Good evening, i want to know like in sql in oracle what will be the difference between the (SYSDATE-hire_date)/12 AS MONTHS and MONTHS_BETWEEN(SYSDATE, hire_date) as both yields different result. Thanks in advance
Software Engineer
  • 471
  • 1
  • 4
  • 20