VB.NET - compare between the computer date & date saved in databased

Asked By mustafa muhseen on 28-Jan-12 09:21 AM

hi i have a project designed by v.b 2008 & access 2007 the databased call name is newdatabased contain table named table1 after some Mathematical operations the program saved date in db i want to compare between the date saved in all recored in db every day with computer date and then display all the recored Which corresponds to the historic IN LISTBOX 

Venkat K replied to mustafa muhseen on 28-Jan-12 09:25 AM
Use DateTime.Compare to compare the dates:

DateTime date1 = DateTime.Now;
DateTime date2 =
dr[o] //or value which is retrieved from database
int result = DateTime.Compare(date1, date2);
string relationship;

if (result < 0)
   relationship = "is earlier than";
else if (result == 0)
   relationship = "is the same time as";    
else
   relationship = "is later than";
Thanks
D Company replied to mustafa muhseen on 28-Jan-12 10:33 AM
hello,

do like this.

//get date from system and pass the date value from your UI to DB and than get the records which satisfied the condition
like this

SELECT * FROM tblname WHERE (NotificationDate = #+ selD+#


Regards
D
[)ia6l0 iii replied to mustafa muhseen on 28-Jan-12 11:39 AM
The word "computer date" should be defined very clearly. And it can cause your design to fail if you don't decide on its definition. 

According to me, date comparison should happen between two values which either reside at the same source or get generated by the same source. So in your case, for efficient calculations and to avoid timezone, incorrect time setup issues you should compare the dates in the database alone. i.e. both the dates  - today's date and db date should be generated and compared in the database itself.

So in Access, you would do this:
=DateDiff(“d”, Now(), [tablename].[columnname])

Hope it helps
Jitendra Faye replied to mustafa muhseen on 28-Jan-12 12:16 PM
While comparing front end date with stored date first it to date format.
and passthis converted date to select command.

like this-

select * from tablename
where datecol =' " + Convert.ToDateTime(frontenddate) + " '

Use this command and let me know.
Jitendra Faye replied to mustafa muhseen on 28-Jan-12 12:16 PM
While comparing front end date with stored date first it to date format.
and passthis converted date to select command.

like this-

select * from tablename
where datecol =' " + Convert.ToDateTime(frontenddate) + " '

Use this command and let me know.