compare

C# object is not null but (myObject != null) still return false

心不动则不痛 提交于 2019-11-27 20:10:49
I need to do a comparaison between an object and NULL. When the object is not NULL I fill it with some data. Here is the code : if (region != null) { .... } This is working but when looping and looping sometime the region object is NOT null (I can see data inside it in debug mode). In step-by-step when debugging, it doesn't go inside the IF statement... When I do a Quick Watch with these following expression : I see the (region == null) return false, AND (region != null) return false too... why and how? Update Someone point out that the object was == and != overloaded: public static bool

Javascript compare two dates to get a difference

梦想与她 提交于 2019-11-27 19:37:49
问题 I am trying to compare two different dates to see if the date inputted is after 7 days of todays date. I have done a bit of googling and come up with this: function val_date(input){ var date = new Date(input); date = date.getTime() / 1000; var timestamp = new Date().getTime() + (7 * 24 * 60 * 60 * 1000) window.alert("Date: "+date + " = N_Date: "+timestamp); if(timestamp > date || timestamp === date){ // The selected time is less than 7 days from now return false; } else if(timestamp < date){

Bash script compare two date variables [duplicate]

末鹿安然 提交于 2019-11-27 19:25:43
This question already has an answer here: How to calculate time elapsed in bash script? 18 answers I'm trying to compare a date given by a user to a date in a file, basically a text file with lots of dates and times listed. for example the user would enter a date such as 22/08/2007 and a time of 1:00, what i need the script to do is count how many dates in the text file are after the date given by the user. I’ve managed to accomplish this by converting each date in the text file to unix timestamp and then comparing the two. Is there no way of simply comparing two dates in bash? Thanks in

How to tell if a date is between two other dates in Python?

家住魔仙堡 提交于 2019-11-27 19:16:58
I have the following codes: if date in (start, end): print 'in between' else: print 'No!' date, start and end are all variables with the format of 1/1. What should I do to have it print out the right result? i tried date as 10/2, start as 3/14 and end as 11/7 and it's print 'No!', which means it's not running right. I guess have to format them to a date format and then compare them. Thanks for any help! As you are still not satisfied, I have another answer for you. Without using datetime and year. It just uses built-in tuples and comparing them: d1 = (3, 28) d2 = (3, 31) d3 = (4, 2) if d1 < d2

Compare files with awk

风格不统一 提交于 2019-11-27 19:11:57
Hi I have two similar files (both with 3 columns). I'd like to check if these two files contains the same elements (but listed in a different orders). First of all I'd like to compare only the 1st columns file1.txt "aba" 0 0 "abc" 0 1 "abd" 1 1 "xxx" 0 0 file2.txt "xyz" 0 0 "aba" 0 0 "xxx" 0 0 "abc" 1 1 How can I do it using awk? I tried to have a look around but I've found only complicate examples. What if I want to include also the other two columns on the comparison? The output should give me the number of matching elements. To print the common elements in both files: $ awk 'NR==FNR{a[$1]

Sort an array in the same order of another array

笑着哭i 提交于 2019-11-27 18:35:32
问题 I have a few arrays of 50+ names like this. ["dan", "ryan", "bob", "steven", "corbin"] ["bob", "dan", "steven", "corbin"] I have another array that has the correct order. Note that the second array above does not include all of the names, but I still want it to follow the order of the following: ["ryan", "corbin", "dan", "steven", "bob"] There is no logical order to it, they are just in this order. What makes sense to me is to compare each array against the correctly ordered one. I think I

Find oldest/youngest datetime object in a list

时光毁灭记忆、已成空白 提交于 2019-11-27 18:04:28
I've got a list of datetime objects, and I want to find the oldest or youngest one. Some of these dates might be in the future. from datetime import datetime datetime_list = [ datetime(2009, 10, 12, 10, 10), datetime(2010, 10, 12, 10, 10), datetime(2010, 10, 12, 10, 10), datetime(2011, 10, 12, 10, 10), #future datetime(2012, 10, 12, 10, 10), #future ] What's the most optimal way to do so? I was thinking of comparing datetime.now() to each one of those. Oldest: oldest = min(datetimes) Youngest before now: now = datetime.datetime.now(pytz.utc) youngest = max(dt for dt in datetimes if dt < now)

Mysql Compare two datetime fields

别说谁变了你拦得住时间么 提交于 2019-11-27 17:50:22
I want to compare two dates with time, I want all the results from tbl where date1 > date2 Select * From temp where mydate > '2009-06-29 04:00:44'; but it is just comparing dates not time. it is giving me all the result set of today's date '2009-06-29 11:08:57' '2009-06-29 11:14:35' '2009-06-29 11:12:38' '2009-06-29 11:37:48' '2009-06-29 11:52:17' '2009-06-29 12:12:50' '2009-06-29 12:13:38' '2009-06-29 12:19:24' '2009-06-29 12:27:25' '2009-06-29 12:28:49' '2009-06-29 12:35:54' '2009-06-29 12:36:54' '2009-06-29 12:49:57' '2009-06-29 12:58:04' '2009-06-29 04:13:20' '2009-06-29 04:56:19' '2009-06

Compare the difference between two list<string>

独自空忆成欢 提交于 2019-11-27 17:36:48
问题 I'am trying to check the difference between two List<string> in c# . Example: List<string> FirstList = new List<string>(); List<string> SecondList = new List<string>(); The FirstList is filled with the following values: FirstList.Add("COM1"); FirstList.Add("COM2"); The SecondList is filled with the following values: SecondList.Add("COM1"); SecondList.Add("COM2"); SecondList.Add("COM3"); Now I want to check if some values in the SecondList are equal to values in the FirstList . If there are

Is comparing to zero faster than comparing to any other number?

北慕城南 提交于 2019-11-27 16:43:47
问题 Is if(!test) faster than if(test==-1) I can produce assembly but there is too much assembly produced and I can never locate the particulars I'm after. I was hoping someone just knows the answer. I would guess they are the same unless most CPU architectures have some sort of "compare to zero" short cut. thanks for any help. 回答1: Typically, yes. In typical processors testing against zero, or testing sign (negative/positive) are simple condition code checks. This means that instructions can be