date-arithmetic

Add Day to Timestamp

一曲冷凌霜 提交于 2019-12-19 12:38:33
问题 How do I add days to a timestamp? If my timestamp is 01-JAN-2011 11-09-05 and I add 2 days, I want 03-JAN-2011 11-09-05 . 回答1: select '01-jan-2011 11-09-05' + interval '2' day 回答2: A completely Oracle-centric solution is to simply add 2 to the timestamp value as the default interval is days for Oracle dates/timestamps: SELECT TO_TIMESTAMP('01-jan-2011 11-09-05','DD-Mon-YYYY HH24-MI-SS') + 2 FROM dual; 来源: https://stackoverflow.com/questions/6142916/add-day-to-timestamp

How to get the number of days in a month?

∥☆過路亽.° 提交于 2019-12-18 12:49:19
问题 I am trying to get the following in Postgres: select day_in_month(2); Expected output: 28 Is there any built-in way in Postgres to do that? 回答1: SELECT DATE_PART('days', DATE_TRUNC('month', NOW()) + '1 MONTH'::INTERVAL - '1 DAY'::INTERVAL ) Substitute NOW() with any other date. 回答2: Using the smart "trick" to extract the day part from the last date of the month, as demonstrated by Quassnoi. But it can be a bit simpler / faster: SELECT extract(days FROM date_trunc('month', now()) + interval '1

SQL: Get records created in time range for specific dates

谁都会走 提交于 2019-12-18 12:27:46
问题 I have a set of records that were created last week, and from those I want to retrieve only those that were created between 6h45 and 19h15. I have a column creation_date that I can use. How can I do this in sql? 回答1: In Oracle we can turn dates into numbers and apply arithmetic to them in a variety of ways. For instance sysdate-7 gives us the date seven days ago. trunc(some_date) removes the time element from a date column. And to_char(some_date, 'SSSSS') gives us its time element as the

How do I calculate number of given weekday between range using Moment JS?

走远了吗. 提交于 2019-12-17 19:52:57
问题 How do I find out how many of a given weekday (ex: Tuesdays) are in a date range using Moment JS and jQuery? I can find the number of days using Difference: http://momentjs.com/docs/#/displaying/difference/ And I know the start and end date, so I feel like it should be possible? Example: How many Tuesdays are there between March 1st and March 25th? 回答1: I came up with the following function that seems to work for the given handful of test cases I tried: function weekdaysBetween(d1, d2,

ISO week number in CMD

给你一囗甜甜゛ 提交于 2019-12-17 19:44:45
问题 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? 回答1: You can use Ritchie Lawrences's Date Functions. It is maintained on Gitub. https://ritchielawrence.github.io/batchfunctionlibrary/ Here is the code. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :DateToWeek %yy% %mm% %dd% yn cw dw :: :: By:

Arithmetics on calendar dates in C or C++ (add N days to given date)

為{幸葍}努か 提交于 2019-12-17 16:32:10
问题 I have been given a date, Which I am taking as an input like (day, month, year): 12, 03, 87 . Now I need to find out the date after n days. I have written code for this, But its not efficient. Can you please tell me any good logic which works faster and have less complexity. #include <stdio.h> static int days_in_month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int day, month, year; unsigned short day_counter; int is_leap(int y) { return ((y % 4 == 0 && y % 100 != 0) || y % 400

MySQL Select last 7 days

左心房为你撑大大i 提交于 2019-12-17 09:36:20
问题 I read some Posts here and seems like nothing special but I can not still select the entries of the last days. SELECT p1.kArtikel, p1.cName, p1.cKurzBeschreibung, p1.dLetzteAktualisierung, p1.dErstellt, p1.cSeo, p2.kartikelpict, p2.nNr, p2.cPfad FROM tartikel AS p1 WHERE DATE(dErstellt) > (NOW() - INTERVAL 7 DAY) INNER JOIN tartikelpict AS p2 ON (p1.kArtikel = p2.kArtikel) WHERE (p2.nNr = 1) ORDER BY p1.kArtikel DESC LIMIT 100;', $connection); If I add the between today and last 7 days my

POSIXct times around DST?

半世苍凉 提交于 2019-12-13 14:20:41
问题 I want to subtract 1 day from a POSIX date and end up at the same time around DST. For example, when I add a day: > as.POSIXct('2009-03-08 23:00:00.000') + 86400 [1] "2009-03-09 23:00:00 EDT" But when I go past, it offsets: > as.POSIXct('2009-03-08 23:00:00.000') - 86400 [1] "2009-03-07 22:00:00 EST" What's the best way to deal with absolute time differences around DST? Usually I deal with this by converting the times into strings and dealing with them separately so that DST isn't applied.

How can I make a program that reads the date(hour,minutes,seconds) then it subtracts it from the second date

荒凉一梦 提交于 2019-12-13 10:28:35
问题 I have a task to create a program where the user gives the Hour, Minute, Second, then he gives another Hour, Minute, Second then the program should substract the second date from the first one. I have been trying to not use the date format, but I can't get it to work. The date has to be in a 24h format, and these two dates have to be in the same day. So if I write 12:59:59 then I couldn't set the second date to 12:59:58 just 13:00:00 . 回答1: Here is an approach how i would do it. var hours1,

How to add 2 dates in Oracle sp? [closed]

我是研究僧i 提交于 2019-12-13 09:26:26
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . How can we add two dates in oracle? For example in sql we can do this, " date_1 + date_2 " how can we achieve the same thing in Oracle 回答1: Adding two dates together would be meaningless but you can add an