date-range

Algorithm to combine / merge date ranges

做~自己de王妃 提交于 2019-11-28 01:44:12
问题 I am trying to find the best way on how to merge date ranges into one database record (array element). This is the data I have: Array ( [0] => Array ( [id] => 18298 [start_date] => 2011-07-09 [end_date] => 2011-10-01 ) [1] => Array ( [id] => 18297 [start_date] => 2011-06-01 [end_date] => 2011-06-30 ) [2] => Array ( [id] => 17113 [start_date] => 2011-03-31 [end_date] => 2011-05-31 ) [3] => Array ( [id] => 20555 [start_date] => 2011-01-03 [end_date] => 2011-03-31 ) ) And after we combine them,

Designing non-overlapping date-time events

巧了我就是萌 提交于 2019-11-27 19:39:48
问题 I have the following problem: Events have a "begin" and "end" time and an amount. I use MySQL DATETIME for both. Now if I have a constraint that says "no overlapping events" I need to make some checks etc. but how to design that? The user only needs 5-mins precision or so, but i want to do calculations with seconds since that is "simpler"/"cleaner" If I have an event (A) with start-end "YYYY-MM-DD 12:00:00"-"YYYY-MM-DD 14:00:00" and another (B) "YYYY-MM-DD 14:00:00"-"YYYY-MM-DD 16:15:00" ->

Should I make a DateRange object?

只谈情不闲聊 提交于 2019-11-27 19:34:41
A few of my domain objects contain date ranges as a pair of start and end date properties: public class Period { public DateTime EffectiveDate { get; set; } public DateTime ThroughDate { get; set; } } public class Timeline { public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } } And I find myself with a lot of this: abstract public int Foo(DateTime startDate, DateTime endDate); abstract public decimal Bar(DateTime startDate, DateTime endDate); abstract public ICollection<C5.Rec<DateTime, DateTime>> FooBar(DateTime startDate, DateTime endDate); The last one made me

Subsetting data.table set by date range in R

杀马特。学长 韩版系。学妹 提交于 2019-11-27 19:21:50
I have a large dataset in data.table that I'd like to subset by a date range. My data set looks like this: testset <- data.table(date=as.Date(c("2013-07-02","2013-08-03","2013-09-04", "2013-10-05","2013-11-06")), yr = c(2013,2013,2013,2013,2013), mo = c(07,08,09,10,11), da = c(02,03,04,05,06), plant = LETTERS[1:5], product = as.factor(letters[26:22]), rating = runif(25)) I'd like to be able to choose a date range directly from the as.Date column without using the yr , mo , or da columns. Currently, I'm subsetting by mo and it's extremely clunky at times, especially when years switch over. A

jQuery UI Datepicker - Date range - Highlight days in between

旧城冷巷雨未停 提交于 2019-11-27 16:40:47
问题 I'm looking for a way of highlighting the days in between the date range of 2 inputs on mouse over. This example is nearly doing what I want to achieve: http://hackingon.net/files/jquery_datepicker/range.htm Only difference is that the highlighting of the selected range should happen on two separate datepickers and on mouse over. Any suggestions? Update: Ok, a bit more details: After selecting a date from the first datepicker, the second datepicker should highlight the previous selected date.

How to group continuous ranges using MySQL

点点圈 提交于 2019-11-27 15:36:49
I have a table that contains categories, dates and rates. Each category can have different rates for different dates, one category can have only one rate at a given date. Id CatId Date Rate ------ ------ ------------ --------- 000001 12 2009-07-07 1 000002 12 2009-07-08 1 000003 12 2009-07-09 1 000004 12 2009-07-10 2 000005 12 2009-07-15 1 000006 12 2009-07-16 1 000007 13 2009-07-08 1 000008 13 2009-07-09 1 000009 14 2009-07-07 2 000010 14 2009-07-08 1 000010 14 2009-07-10 1 Unique index (catid, Date, Rate) I would like for each category to group all continuous dates ranges and keep only the

Get all dates in date range in SQL Server

旧时模样 提交于 2019-11-27 14:33:01
I got this example from one StackOverflow question that was asked but I couldn't get it work according to my need. WITH DateTable AS ( SELECT CAST('20110101' as Date) AS [DATE] UNION ALL SELECT DATEADD(dd, 1, [DATE]) FROM DateTable WHERE DATEADD(dd, 1, [DATE]) < cast('20110131' as Date) ) SELECT dt.[DATE] FROM [DateTable] dt Input- ID | FromDate | ToDate ============================= 1 | 2011-11-10 | 2011-11-12 2 | 2011-12-12 | 2011-12-14 Output - SN | Dates | ================== 1 | 2011-11-10 | 2 | 2011-11-11 | 3 | 2011-11-12 | 4 | 2011-12-12 | 5 | 2011-12-13 | 6 | 2011-12-14 | See this code

Check if date is within time range using Joda or standard Java API

佐手、 提交于 2019-11-27 13:49:31
问题 I have first time as string '12:00:00' and another '19:00:00'. How to check time portion of the day is within these time values? 回答1: Using Joda Time you could do something like this: DateTime start = new DateTime(2010, 5, 25, 12, 0, 0, 0); DateTime end = new DateTime(2010, 5, 25, 21, 0, 0, 0); Interval interval = new Interval(start, end); DateTime test = new DateTime(2010, 5, 25, 16, 0, 0, 0); System.out.println(interval.contains(test)); 回答2: Create calendar instances of the start and end

Grep inside all files created within date range

夙愿已清 提交于 2019-11-27 12:43:18
I am on the Ubuntu OS. I want to grep a word (say XYZ) inside all log files which are created within date range 28-may-2012 to 30-may-2012. How do I do that? This is a little different from Banthar's solution, but it will work with versions of find that don't support -newermt and it shows how to use the xargs command, which is a very useful tool. You can use the find command to locate files "of a certain age". This will find all files modified between 5 and 10 days ago: find /directory -type f -mtime -10 -mtime +5 To then search those files for a string: find /directory -type f -mtime -10

SQL Server : fetching records between two dates?

萝らか妹 提交于 2019-11-27 11:41:49
问题 In SQL I write a SELECT statement to fetch data between two dates, using between and Ex: select * from xxx where dates between '2012-10-26' and '2012-10-27' But the rows returned are for 26th only, not 26th and 27th. Can you help me? Thank you. 回答1: As others have answered, you probably have a DATETIME (or other variation) column and not a DATE datatype. Here's a condition that works for all, including DATE : SELECT * FROM xxx WHERE dates >= '20121026' AND dates < '20121028' --- one day after