date-range

Designing non-overlapping date-time events

让人想犯罪 __ 提交于 2019-11-28 14:44:08
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" -> they are non-overlapping even though they both contain 14:00:00. In order to determine that they are

Java Generate all dates between x and y [duplicate]

ε祈祈猫儿з 提交于 2019-11-28 14:07:04
This question already has an answer here: how to get a list of dates between two dates in java 21 answers I attempted to generate the date range between date x and date y but failed. I have the same method in c# so I tried to modify it as much as I can but failed to get result. Any idea what I could fix? private ArrayList<Date> GetDateRange(Date start, Date end) { if(start.before(end)) { return null; } int MILLIS_IN_DAY = 1000 * 60 * 60 * 24; ArrayList<Date> listTemp = new ArrayList<Date>(); Date tmpDate = start; do { listTemp.add(tmpDate); tmpDate = tmpDate.getTime() + MILLIS_IN_DAY; } while

C# seconds since specific date

北慕城南 提交于 2019-11-28 13:22:05
In C# 3.0, how do I get the seconds since 1/1/2010? MadBoy Goes like this: TimeSpan test = DateTime.Now - new DateTime(2010, 01, 01); MessageBox.Show(test.TotalSeconds.ToString()); For one liner fun: MessageBox.Show((DateTime.Now - new DateTime(2010, 01, 01)) .TotalSeconds.ToString()); You can substract 2 DateTime instances and get a TimeSpan: DateTime date = new DateTime(2010,1,1); TimeSpan diff = DateTime.Now - date; double seconds = diff.TotalSeconds; Just to avoid timezone issues TimeSpan t = (DateTime.UtcNow - new DateTime(2010, 1, 1)); int timestamp = (int) t.TotalSeconds; Console

MySQL Check if date range is in date range

岁酱吖の 提交于 2019-11-28 12:50:40
问题 Having trouble making a SQL query for a small booking system, i have a table containing two entries which holds two different dates and a number. Nr DateFrom DateTo ---------------------------- 1 2015-01-01 2015-01-03 2 2015-01-05 2015-01-08 I want to query where i can enter two different dates and only return the number of the date range in the table that doesn't collide with the entered date range. For example if i enter the dates 2015-01-02 and 2015-01-04 it would return Nr 2 and 2015-01

Using IEqualityComparer GetHashCode with a tolerance

十年热恋 提交于 2019-11-28 12:46:33
I am trying to implement an IEqualityComparer that has a tolerance on a date comparison. I have also looked into this question . The problem is that I can't use a workaround because I am using the IEqualityComparer in a LINQ .GroupJoin() . I have tried a few implementations that allow for tolerance. I can get the Equals() to work because I have both objects but I can't figure out how to implement GetHashCode() . My best attempt looks something like this: public class ThingWithDateComparer : IEqualityComparer<IThingWithDate> { private readonly int _daysToAdd; public ThingWithDateComparer(int

Weekly total sums

送分小仙女□ 提交于 2019-11-28 10:32:31
问题 I have a table in a PostgreSQL database containing dates and a total count per day. mydate total 2012-05-12 12 2012-05-14 8 2012-05-13 4 2012-05-12 12 2012-05-15 2 2012-05-17 1 2012-05-18 1 2012-05-21 1 2012-05-25 1 Now I need to get the weekly totals for a given date range. Ex. I want to get the weekly totals from 2012-05-01 up to 2012-05-31 . I'm looking at this output: 2012-05-01 2012-05-07 0 2012-05-08 2012-05-14 36 2012-05-15 2012-05-22 5 2012-05-23 2012-05-29 1 2012-05-30 2012-05-31 0

SQL join against date ranges?

送分小仙女□ 提交于 2019-11-28 05:25:46
Consider two tables: Transactions , with amounts in a foreign currency: Date Amount ========= ======= 1/2/2009 1500 2/4/2009 2300 3/15/2009 300 4/17/2009 2200 etc. ExchangeRates , with the value of the primary currency (let's say dollars) in the foreign currency: Date Rate ========= ======= 2/1/2009 40.1 3/1/2009 41.0 4/1/2009 38.5 5/1/2009 42.7 etc. Exchange rates can be entered for arbitrary dates - the user could enter them on a daily basis, weekly basis, monthly basis, or at irregular intervals. In order to translate the foreign amounts to dollars, I need to respect these rules: A. If

MVC Model Range Validator?

大城市里の小女人 提交于 2019-11-28 04:33:11
问题 i wnat to validate the datetime, My Code is: [Range(typeof(DateTime), DateTime.Now.AddYears(-65).ToShortDateString(), DateTime.Now.AddYears(-18).ToShortDateString(), ErrorMessage = "Value for {0} must be between {1} and {2}")] public DateTime Birthday { get; set; } but i get the error: An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type please help me? 回答1: This means the values for the Range attribute can't be

Date range picker on jquery ui datepicker

ぐ巨炮叔叔 提交于 2019-11-28 04:12:18
I created a date range picker using jquery ui where you can use the same inline calendar to make both of your date selections. See my fiddle here: http://jsfiddle.net/kVsbq/4/ JS $(".datepicker").datepicker({ minDate: 0, numberOfMonths: [12, 1], beforeShowDay: function (date) { var date1 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#input1").val()); var date2 = $.datepicker.parseDate($.datepicker._defaults.dateFormat, $("#input2").val()); return [true, date1 && ((date.getTime() == date1.getTime()) || (date2 && date >= date1 && date <= date2)) ? "dp-highlight" : ""]; },

Merge overlapping time intervals, how?

限于喜欢 提交于 2019-11-28 02:19:27
问题 Anyone could help me in a query that **merge a interval of datas? ex: Common select: SELECT id, date_start, date_end FROM evento ORDER BY date_start I GOT THIS: FROM THIS: but a want a query that return this: 01 - 2013-10-11 08:00:00 2013-10-11 15:00:00 02 - 2013-10-11 16:00:00 2013-10-11 19:00:00 Thanks a lot! 回答1: You may also try this query (once more solutions beside those given by PM 77-1 in the comment above) : WITH RECURSIVE cte( id, date_start, date_end ) AS ( SELECT id, date_start,