Click here to Skip to main content
15,907,392 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I was just comparing the two array values. The first array has the time value (15:34) and the second array have exact same of the first array but without the time. I want to check both are equal, just skip the time (15:34) other values are I need to compare. How can I do this?

For Example:-
A[] = {Yes, No, 15 Sep 14 15:34, Unverified}
B[] = {Yes, No, 15 Sep 14, Unverified}
Expected Result : True

A[] = {Yes, No, 15 Sep 14 15:34, Unverified}
B[] = {Yes, No, 15 Sep 14, verified}
Expected Result : False (i.e., verified is different in the B[])
Posted
Updated 16-Sep-14 9:04am
v2
Comments
BillWoodruff 16-Sep-14 20:28pm    
The only way your Array declarations could be "legal" is if they are Type Dynamic. Is that the case, here ?

Compare the time values using the DateTime.Date property: it removes any time component.

By the way: that's a pretty poor way to store information. You would be much better off creating a class to hold the data and writing a comparer for the class.
C#
public class MyData
   {
   public bool YesOrNo { get; set; }
   public bool NoOrYes { get; set; }
   public DateTime Date { get; set; }
   public string ExtraData { get; set; }
   }
using an array to hold different datatypes is a good way to introduce bugs and problems to you code (and complicate the usage of the data as well)
 
Share this answer
 
Comments
vasanthkumarmk 16-Sep-14 15:09pm    
The actual scenario is i am using to compare the to CSV Format files. One file is constant file has contains the date format with time. Another file i have the only date in the same column. So i will get both details in the array[] then i will compare these data.

So i just want to compare with time and without time is important in my scenario. I hope you understanding is clear now.
OriginalGriff 17-Sep-14 4:15am    
That implies you are doing some very wrong things: like taking a line from teh CSV, and using Split on a comma to separate the fields: don't. It tends to fail in really nasty ways when you get "real" csv data like:
Joe,Smith,"2, The Larches", Kelvldon
Because it doesn't take into account the comma within the double quoted field.
There are some good articles which provide better ways to read CSV file: use them!
And then, convert your fields into "proper" datatypes in an actual class, instead of using an array of objects or strings: it makes the rest of your code a huge amount simpler for a relatively small investment of time to start with.
C#
public class MyData1
   {
   public string col1 { get; set; }
   public string col2 { get; set; }
   public DateTime col3 { get; set; }
   public string ExtraData { get; set; }
   }

public class MyData2
   {
   public string col1 { get; set; }
   public string col2 { get; set; }
   public DateTime col3 { get; set; }
   public string ExtraData { get; set; }
   }




while compare , make col3 as

MyData1.col3.ToShortDateString() = MyData2.col3.ToShortDateString()

it will check only with date
 
Share this answer
 
Comments
vasanthkumarmk 16-Sep-14 15:41pm    
I have the combination of array, not only date. I have string, int, date in my array
Ex : A[] = {Yes, No, 15 Sep 14 15:34, Unverified}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900