datetime-comparison

Why datetime cannot compare?

ⅰ亾dé卋堺 提交于 2019-12-06 16:29:59
问题 my C# unit test has the following statement: Assert.AreEqual(logoutTime, log.First().Timestamp); Why it is failed with following information: Assert.AreEqual failed. Expected:<4/28/2010 2:30:37 PM>. Actual:<4/28/2010 2:30:37 PM>. Are they not the same? Update: Use this if you only care to second: Assert.AreEqual(logoutTime.ToString(), log.First().Timestamp.ToString()); 回答1: Have you verified that the number of ticks/milliseconds are equal? If you do DateTime.Now() twice back to back, they

Why datetime cannot compare?

帅比萌擦擦* 提交于 2019-12-04 23:37:13
my C# unit test has the following statement: Assert.AreEqual(logoutTime, log.First().Timestamp); Why it is failed with following information: Assert.AreEqual failed. Expected:<4/28/2010 2:30:37 PM>. Actual:<4/28/2010 2:30:37 PM>. Are they not the same? Update: Use this if you only care to second: Assert.AreEqual(logoutTime.ToString(), log.First().Timestamp.ToString()); Dinah Have you verified that the number of ticks/milliseconds are equal? If you do DateTime.Now() twice back to back, they will appear to be the same number down to the minute and probably even down to the second , but they will

How to determine if the specific time is between given time range in javascript

狂风中的少年 提交于 2019-12-01 06:03:48
i want to check var check_val in between two time var open_time and var close_time var open_time = "23:30"; var close_time = "06:30"; var check_val ="02:30"; if(Date.parse ( check_val ) > Date.parse ( open_time ) && Date.parse ( check_val ) < Date.parse ( close_time )){ var flag=1; } else { var flag=2 } the result is always else part Date.parse() accepts dates in RFC2822 or ISO8601 formats. In your case, it always returns NaN . Date.parse("23:30"); // NaN Using the appropriate Date format works as expected: var open_time = Date.parse("2011-10-09T23:30"); var close_time = Date.parse("2011-10

How to determine if the specific time is between given time range in javascript

折月煮酒 提交于 2019-12-01 03:23:22
问题 i want to check var check_val in between two time var open_time and var close_time var open_time = "23:30"; var close_time = "06:30"; var check_val ="02:30"; if(Date.parse ( check_val ) > Date.parse ( open_time ) && Date.parse ( check_val ) < Date.parse ( close_time )){ var flag=1; } else { var flag=2 } the result is always else part 回答1: Date.parse() accepts dates in RFC2822 or ISO8601 formats. In your case, it always returns NaN . Date.parse("23:30"); // NaN Using the appropriate Date

How to do date/time comparison

被刻印的时光 ゝ 提交于 2019-11-28 17:16:47
问题 Is there any options in doing date comparison in Go? I have to sort data based on date and time - independently. So I might allow an object that occurs within a range of dates so long as it also occurs within a range of times. In this model, I could not simply just select the oldest date, youngest time/latest date, latest time and Unix() seconds compare them. I'd really appreciate any suggestions. Ultimately, I wrote a time parsing string compare module to check if a time is within a range.

Safely comparing local and universal DateTimes

[亡魂溺海] 提交于 2019-11-28 06:44:12
I just noticed what seems like a ridiculous flaw with DateTime comparison. DateTime d = DateTime.Now; DateTime dUtc = d.ToUniversalTime(); d == dUtc; // false d.Equals(dUtc); //false DateTime.Compare(d, dUtc) == 0; // false It appears that all comparison operations on DateTimes fail to do any type of smart conversion if one is DateTimeKind.Local and one is DateTimeKind.UTC. Is the a better way to reliably compare DateTimes aside from always converting both involved in the comparison to utc time? Abel Edited, my original answer was partially incorrect: When you call .Equal or .Compare ,

How do I perform Date Comparison in EF query?

浪子不回头ぞ 提交于 2019-11-27 04:27:38
Please help. I am trying to figure out how to use DATE or DATETIME for comparison in a linq query. Example: If I wanted all Employee names for those who started before today, I would do something like this in SQL: SELECT EmployeeNameColumn FROM EmployeeTable WHERE StartDateColumn.Date <= GETDATE() //Today But what about linq? DateTime startDT = //Today var EmployeeName = from e in db.employee where e.StartDateColumn <= startDT The above WHERE doesn't work: Exception Details: System.NotSupportedException: The specified type member 'Date' is not supported in LINQ to Entities. Only initializers,

Safely comparing local and universal DateTimes

早过忘川 提交于 2019-11-27 01:27:47
问题 I just noticed what seems like a ridiculous flaw with DateTime comparison. DateTime d = DateTime.Now; DateTime dUtc = d.ToUniversalTime(); d == dUtc; // false d.Equals(dUtc); //false DateTime.Compare(d, dUtc) == 0; // false It appears that all comparison operations on DateTimes fail to do any type of smart conversion if one is DateTimeKind.Local and one is DateTimeKind.UTC. Is the a better way to reliably compare DateTimes aside from always converting both involved in the comparison to utc

How to compare only date components from DateTime in EF?

时光总嘲笑我的痴心妄想 提交于 2019-11-26 09:08:44
问题 I am having two date values, one already stored in the database and the other selected by the user using DatePicker. The use case is to search for a particular date from the database. The value previously entered in the database always has time component of 12:00:00, where as the date entered from picker has different time component. I am interested in only the date components and would like to ignore the time component. What are the ways to do this comparison in C#? Also, how to do this in