date-arithmetic

Calculate Date/Time Difference in Java considering AM/PM

巧了我就是萌 提交于 2019-11-27 16:35:23
问题 I want to calculate the difference between two date/time in java using Date and Calendar classes. The format that I have is "2012-01-24 12:30:00 PM". I have implemented my own method and also google it to work with others, but haven't getting the right hint to handle AM and PM values. The date/time difference got troubled whenever the time have 12(AM/PM) in it. For example if I have date/time "2012-01-24 12:30:00 PM" and "2012-01-24 02:30:00 PM" it shows the difference is 10 hours.

Date comparison returns unusual result - SQL Oracle

China☆狼群 提交于 2019-11-27 15:54:22
I have a table of the structure: +---------+--------------+-----------------+---------------+-------+------+ | week_no | long_week_no | week_start_date | week_end_date | month | year | +---------+--------------+-----------------+---------------+-------+------+ | 1 | 1A | 01/01/2015 | 03/01/2015 | JAN | 2015 | | 1 | 1B | 04/01/2015 | 10/01/2015 | JAN | 2015 | | 2 | 2 | 11/01/2015 | 17/01/2015 | JAN | 2015 | | 3 | 3 | 18/01/2015 | 24/01/2015 | JAN | 2015 | | .. | .. | .. | .. | .. | .. | | 51 | 51 | 14/12/2014 | 20/12/2015 | DEC | 2014 | +---------+--------------+-----------------+--------------

How to calculate an age based on a birthday? [duplicate]

為{幸葍}努か 提交于 2019-11-27 14:31:39
问题 Possible Duplicate: How do I calculate someone’s age in C#? I want to write an ASP.NET helper method which returns the age of a person given his or her birthday. I've tried code like this: public static string Age(this HtmlHelper helper, DateTime birthday) { return (DateTime.Now - birthday); //?? } But it's not working. What is the correct way to calculate the person's age based on their birthday? 回答1: Stackoverflow uses such function to determine the age of a user. Calculate age in C# The

MySQL Select last 7 days

最后都变了- 提交于 2019-11-27 13:09:07
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 Code will not output anything. The WHERE clause is misplaced, it has to follow the table references and

Oracle Date - How to add years to date

人走茶凉 提交于 2019-11-27 09:11:45
I have a date field DATE = 10/10/2010 sum = 4 (this are number of years by calculation) is there a way to add four years to 10/10/2010 and make it 10/10/2014? Try adding months (12 * number of years) instead. Like this- add_months(date'2010-10-10', 48) Use add_months Example: SELECT add_months( to_date('10-OCT-2010'), 48 ) FROM DUAL; Warning add_months, returns the last day of the resulting month if you input the last day of a month to begin with. So add_months(to_date('28-feb-2011'),12) will return 29-feb-2012 as a result. I believe you could use the ADD_MONTHS() function. 4 years is 48

Add 2 months to current timestamp

无人久伴 提交于 2019-11-27 08:09:36
问题 How can I add months to a timestamp value in Oracle? In my query, it's getting converted to date value instead: SELECT add_months(current_timestamp,2) FROM dual; The actual output is: ADD_MONTH 11-MAR-13 The expected output is: 2013-01-01 00:00:00.000000000+00:00 回答1: This will give you the date and the time as a TIMESTAMP data type: select TO_TIMESTAMP(TO_CHAR(ADD_MONTHS(SYSDATE, 2), 'YYYYMMDD HH24:MI'), 'YYYYMMDD HH24:MI') from dual; If you need more or less precision (E.G. rounding) than

Find the NSDate for next Monday [closed]

时光怂恿深爱的人放手 提交于 2019-11-27 07:46:07
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . 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? 回答1: This piece of code should get what you want. It simply calculates how many days are from monday and append it from current's date. NSDate

How to subtract years?

不打扰是莪最后的温柔 提交于 2019-11-27 07:12:41
I have a date in R, e.g.: dt = as.Date('2010/03/17') I would like to subtract 2 years from this date, without worrying about leap years and such issues, getting as.Date('2010-03-17') . How would I do that? Shane The easiest thing to do is to convert it into POSIXlt and subtract 2 from the years slot. > d <- as.POSIXlt(as.Date('2010/03/17')) > d$year <- d$year-2 > as.Date(d) [1] "2008-03-17" See this related question: How to subtract days in R? . With lubridate library(lubridate) ymd("2010/03/17") - years(2) You could use seq : R> dt = as.Date('2010/03/17') R> seq(dt, length=2, by="-2 years")[2

How to get a list of months between 2 given dates using a query?

假如想象 提交于 2019-11-27 06:10:11
问题 I have 2 dates, say 28-Mar-2011 and 29-Jun-2011. I need an sql query that will display the months between these 2 dates including the months containing the dates, ie. June, May, April and March. 回答1: Something like this SQL> ed Wrote file afiedt.buf select to_char( add_months( start_date, level-1 ), 'fmMonth' ) from (select date '2011-03-30' start_date, date '2011-06-29' end_date from dual) connect by level <= months_between( trunc(end_date,'MM'), trunc(start_date,'MM') ) * + 1 SQL> / TO_CHAR

Oracle: how to add minutes to a timestamp?

Deadly 提交于 2019-11-27 03:56:34
I need to add 30 minutes to values in a Oracle date column. I do this in my SELECT statement by specifying to_char(date_and_time + (.000694 * 31) which works fine most of the time. But not when the time is on the AM/PM border. For example, adding 30 minutes to 12:30 [which is PM] returns 1:00 which is AM. The answer I expect is 13:00 . What's the correct way to do this? All of the other answers are basically right but I don't think anyone's directly answered your original question. Assuming that "date_and_time" in your example is a column with type DATE or TIMESTAMP, I think you just need to