Comparison of String vb.NET -


i trying compare compare string values.

 dim tod string = "04/02/2016_01:20"  dim dbookto string = "08/02/2014_01:30"  if tod = dbookto    'do  if tod<dbookto   'do  if tod>dbookto   'dosomething  endif  

ideally want here 3rd condition executed because "08/02/2014_01:30" smaller "04/02/2016_01:20". 2nd condition being executed. please me here.

that's because you're performing string comparison, means input compared char char, until first difference found.

first difference on second character, between 4 , 8. , because 4 lower 8 that's makes tod lower dbookto.

to make work , compare values, not string representation have use proper type, in case datetime:

dim tod datetime = new datetime(2016, 2, 4, 1, 20, 0) dim dbookto datetime = new datetime(2014, 2, 8, 1, 30, 0) 

you can datetime instance string using datetime.parseexact method:

dim todstring string = "04/02/2016_01:20" dim dbooktostring string = "08/02/2014_01:30"  dim tod datetime = datetime.parseexact(todstring, "mm/dd/yyyy_hh:mm", system.globalization.datetimeformatinfo.invariantinfo) dim dbookto datetime = datetime.parseexact(dbooktostring, "mm/dd/yyyy_hh:mm", system.globalization.datetimeformatinfo.invariantinfo) 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -