date-arithmetic

How can I calculate what date Good Friday falls on, given a year?

馋奶兔 提交于 2019-11-30 06:26:16
问题 Does anyone have a good algorithm to calculate what date Good Friday falls on given the year as an input? Preferably in C#. 回答1: Here's a great article that should help you build your algorithm http://www.codeproject.com/KB/datetime/christianholidays.aspx Based on this example, you should be able to write: DateTime goodFriday = EasterSunday(DateTime.Now.Year).AddDays(-2); Full Example: public static DateTime EasterSunday(int year) { int day = 0; int month = 0; int g = year % 19; int c = year

How do you find results that occurred in the past week?

时光毁灭记忆、已成空白 提交于 2019-11-30 03:06:54
I have a books table with a returned_date column. I'd like to see the results for all of the books with a returned date that occurred in the past week. Any thoughts? I tried doing some date math, but Postgres wasn't happy with my attempt. Eric You want to use interval and current_date : select * from books where returned_date > current_date - interval '7 days' This would return data from the past week including today. Here's more on working with dates in Postgres. Assuming returned_date is actually data type date , this is simpler, faster and correct: SELECT * FROM books WHERE returned_date >

Oracle DateTime in Where Clause?

懵懂的女人 提交于 2019-11-29 20:14:29
I have sql something like this: SELECT EMP_NAME, DEPT FROM EMPLOYEE WHERE TIME_CREATED >= TO_DATE('26/JAN/2011','dd/mon/yyyy') -> This returns 10 rows and TIME_CREATED = '26-JAN-2011' Now when i do this i don't get any rows back, SELECT EMP_NAME, DEPT FROM EMPLOYEE WHERE TIME_CREATED = TO_DATE('26/JAN/2011','dd/mon/yyyy') -> Took the greater than out Any reason why? Yes: TIME_CREATED contains a date and a time . Use TRUNC to strip the time: SELECT EMP_NAME, DEPT FROM EMPLOYEE WHERE TRUNC(TIME_CREATED) = TO_DATE('26/JAN/2011','dd/mon/yyyy') UPDATE: As Dave Costa points out in the comment below,

Prevention triggers

陌路散爱 提交于 2019-11-29 18:21:37
I have a table like this: StudentID Student Name Birthdate Student Birthplace Gender Height Weight --------- --------------- --------- ------------------ ------ ------ ------ 83 Adam Stone 30-JUN-94 Towson, USA M 193 88 84 Stephanie Love 17-JUN-93 KL,Malaysia F 176 67 85 Rachel Kim 17-FEB-92 Seoul, South Korea F 179 56 How do i write a trigger to prevent any student under the age of 15 from being stored in the student's table? You have a Date of Birth. So you need to determine that the DoB is at least sixteen years before today. There are various different ways of doing this; here's one using

Calculate Difference between dates by group in R

☆樱花仙子☆ 提交于 2019-11-29 16:07:25
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 more simply, the difference between the 1st and last day. I used the following code: HS_Hatch$Exposure=NA for(i in 2:nrow(HS_Hatch)){HS_Hatch$Exposure[i]=HS_Hatch$DateVisit[i]- HS_Hatch$DateVisit[i-1]} where HS_Hatch is my dataset and DateVisit is the actual date. The only problem is R is calculating an exposure value for the 1st date (which doesn't

Using sql DATEADD function in java

拥有回忆 提交于 2019-11-29 11:06:58
When I run queries using DATEADD it seems that the database does not recognize this function. also when I just run select DATEADD(Month, -3, GETDATE()) I'm getting: Error code -1, SQL state 42X01: Syntax error: Encountered "<EOF>" at line 1, column 36. I added the JAR file from hsqldb-2.2.9 as you can see What am I missing here? Derby does not have a DATEADD function. You need to use the JDBC function timestampadd to achieve this: select {fn TIMESTAMPADD(SQL_TSI_MONTH, -3, CURRENT_TIMESTAMP)} from sysibm.sysdummy1 An alternative to using sysdummy1 is the ANSI standard values clause which works

How to get the end of a day?

亡梦爱人 提交于 2019-11-29 10:59:36
I'm using PostgreSQL 8.4 . I have a column of the table my_tbl which contains dates ( timestamp without timezone ). For instance: date ------------------- 2014-05-27 12:03:20 2014-10-30 01:20:03 2013-10-19 16:34:34 2013-07-10 15:24:26 2013-06-24 18:15:06 2012-07-14 07:09:14 2012-05-13 04:46:18 2013-01-04 21:31:10 2013-03-26 10:17:02 How to write an SQL query which returns all dates in the format: xxxx-xx-xx 23:59:59 That's every date will be set to the end of the day. Take the date, truncate it, add one day and subtract one second: select date_trunc('day', date) + interval '1 day' - interval

Create View with 365 days

本秂侑毒 提交于 2019-11-29 07:53:31
How to Create a View with all days in year. view should fill with dates from JAN-01 to Dec-31. How can I do this in Oracle ? If current year have 365 days, view should have 365 rows with dates. if current year have 366 days, view should have 366 rows with dates. I want the view to have a single column of type DATE . This simple view will do it: create or replace view year_days as select trunc(sysdate, 'YYYY') + (level-1) as the_day from dual connect by level <= to_number(to_char(last_day(add_months(trunc(sysdate, 'YYYY'),11)), 'DDD')) / Like this: SQL> select * from year_days; THE_DAY --------

Subtract hours from the now() function

一笑奈何 提交于 2019-11-29 07:52:44
We have a machine running 24x7. Every day I report the number of pieces it produced per hour. In our case one working day means '2015-06-16 06:00:00' to '2015-06-17 06:00:00' for example. Here is my code: select date_trunc('hour', t_el_eventlog.eventtime at time zone 'CET') as hours, count (distinct t_el_eventlog.serialnumber) as count from t_el_eventlog where eventtime at time zone 'CET' between '2015-06-16 06:00:00' and '2015-06-17 06:00:00' and sourceid = '44' group by hours order by hours asc My Postgres version: "PostgreSQL 9.4.1, compiled by Visual C++ build 1800, 32-bit" The data types

How to subtract 2 dates in oracle to get the result in hour and minute

可紊 提交于 2019-11-29 04:05:17
I want to subtract 2 dates and represent the result in hour and minute in one decimal figure. I have the following table and I am doing it in this way but the result is not as desired. There is some slight variation, I'm sure this is simple arithmetic but I'm not getting it right. select start_time, end_time, (end_time-start_time)*24 from come_leav; START_TIME END_TIME (END_TIME-START_TIME)*24 ------------------- ------------------- ------------------------ 21-06-2011 14:00:00 21-06-2011 16:55:00 2.9166667 21-06-2011 07:00:00 21-06-2011 16:50:00 9.8333333 21-06-2011 07:20:00 21-06-2011 16:30