date-arithmetic

Number of days between two dates C++

99封情书 提交于 2019-11-27 01:44:59
I saw examples for C#, Java, but for C++ i cant find solution to calculate how many days between two dates. For example between 2012-01-24 and 2013-01-08 Thanks! This is one way. #include <iostream> #include <ctime> int main() { struct std::tm a = {0,0,0,24,5,104}; /* June 24, 2004 */ struct std::tm b = {0,0,0,5,6,104}; /* July 5, 2004 */ std::time_t x = std::mktime(&a); std::time_t y = std::mktime(&b); if ( x != (std::time_t)(-1) && y != (std::time_t)(-1) ) { double difference = std::difftime(y, x) / (60 * 60 * 24); std::cout << std::ctime(&x); std::cout << std::ctime(&y); std::cout <<

How to count days except Sundays between two dates in Postgres?

三世轮回 提交于 2019-11-26 23:32:27
问题 To find the number of days between two dates we can use something like this: SELECT date_part('day',age('2017-01-31','2017-01-01')) as total_days; In the above query we got 30 as output instead of 31. Why is that? And I also want to find the number of days except Sundays. Expected output for the interval ('2017-01-01', '2017-01-31') : Total Days = 31 Total Days except Sundays = 26 回答1: You need to define "between two dates" more closely. Lower and upper bound included or excluded? A common

How to add a time interval to an NSDate?

删除回忆录丶 提交于 2019-11-26 23:12:43
问题 I have an NSDate and a duration. I need to get the time after the duration Given: The date is "2010-02-24 12:30:00 -1000" duration is 3600 secs I need to get "2010-02-24 13:30:00 -1000" I thought dateWithTimeIntervalSinceReferenceDate: , would do the trick but I see now that this gives a date offset from 1 Jan 2001 GMT. Is there another C function I need to use 回答1: As DyingCactus states, you can use the addTimeInterval method of NSDate, but depending on the OS version is will create a

Get the number of days between two dates in Oracle, inclusive of the dates

只谈情不闲聊 提交于 2019-11-26 22:01:18
问题 I want to get total number of days between two provided dates. I've tried the below query but didn't get the exact different; the last date is not being included. select (to_date ('15-06-13','dd-MM-yyyy') - to_date('01-02-12','dd-MM-yyyy')) from dual This should return 501 days but it is returning 500 days instead. If I add +1 after calculation, then I'm getting the correct result. Do I really need to include +1 or is there an alternate approach to get the actual result? 回答1: In Oracle

Calculating time (adding minutes) bash

大城市里の小女人 提交于 2019-11-26 21:36:23
问题 I got stuck in part of the script. I have time: for example "16:00" and duration in minutes like: 410. Is there any easy way to add those two values? I've tried a lot of combinations with date -d , but can't solve it. 回答1: Try this (Kysu's version): date -d "16:00 410 minutes" +'%H:%M' or this: date -d "16:00 today + 410 minutes" +'%H:%M' But do not use this: date -d "16:00 + 410 minutes" +'%H:%M' # BAD! Strange things happen if you omit the word today but keep the + . (I think the + 410 is

Number of days between two dates - ANSI SQL

亡梦爱人 提交于 2019-11-26 21:27:39
问题 I need a way to determine the number of days between two dates in SQL. Answer must be in ANSI SQL. 回答1: ANSI SQL-92 defines DATE - DATE as returning an INTERVAL type. You are supposed to be able to extract scalars from INTERVALS using the same method as extracting them from DATEs using – appropriately enough – the EXTRACT function (4.5.3). <extract expression> operates on a datetime or interval and returns an exact numeric value representing the value of one component of the datetime or

Calculate business days in Oracle SQL(no functions or procedure)

≡放荡痞女 提交于 2019-11-26 20:47:56
I am trying to calculate business days between two dates in Oracle select. I got to the point when my calculation gives most results correct for given dates (I compare it with NETWORKDAYS in excel) but sometimes it varies from 2 days to -2 days - and I don't know why... Here's my code: SELECT ((to_char(CompleteDate,'J') - to_char(InstallDate,'J'))+1) - (((to_char(CompleteDate,'WW')+ (52 * ((to_char(CompleteDate,'YYYY') - to_char(InstallDate,'YYYY'))))) - to_char(InstallDate,'WW'))*2) as BusinessDays FROM TABLE Thanks! yochim The solution, finally: SELECT OrderNumber, InstallDate, CompleteDate,

How to change the default time zone in R?

房东的猫 提交于 2019-11-26 19:55:01
How can I change the default timezone in R? I'm working with time series. All my time series are defined in UTC time zone, but if I print a date it is always done in CET/CEST time zone. Another way to do it, without changing the whole computer time is using the setenv command like this : Sys.setenv(TZ='GMT') See this good article on changing time zone in R: http://blog.revolutionanalytics.com/2009/06/converting-time-zones.html Shortly (in case the link will be unavailable in the future): # your time string pb.txt <- "2009-06-03 19:30" # convert it to R object for London time zone pb.date <- as

The difference in months between dates in MySQL

天大地大妈咪最大 提交于 2019-11-26 19:42:50
I'm looking to calculate the number of months between 2 date time fields. Is there a better way than getting the unix timestamp and the dividing by 2 592 000 (seconds) and rounding up whithin MySQL? The DATEDIFF function can give you the number of days between two dates. Which is more accurate, since... how do you define a month? (28, 29, 30, or 31 days?) Month-difference between any given two dates: I'm surprised this hasn't been mentioned yet: Have a look at the TIMESTAMPDIFF() function in MySQL. What this allows you to do is pass in two TIMESTAMP or DATETIME values (or even DATE as MySQL

Oracle date “Between” Query

本小妞迷上赌 提交于 2019-11-26 19:22:38
问题 I am using oracle database. i want to execute one query to check the data between two dates. NAME START_DATE ------------- ------------- Small Widget 15-JAN-10 04.25.32.000000 PM Product 1 17-JAN-10 04.31.32.000000 PM select * from <TABLENAME> where start_date BETWEEN '15-JAN-10' AND '17-JAN-10' But I dont get any results from above query. I think I have to use "like" and "%". But I dont know where to use them. Please throw some lights on this. thanks in advance. 回答1: Judging from your output