FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister  MasterVB.NET
Visual Basic 2005 .NET Forum
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
How do I compare dates in ms sql tables in C#?
 
Post new topic   Reply to topic    MasterVB.NET Forum Index -> Database Programming
View previous topic :: View next topic  
Message
Author
srussell
Newbie
Joined: 25 Jul 2006
Posts: 12

PostPosted: Tue Jul 25, 2006 1:00 am    
Post subject: How do I compare dates in ms sql tables in C#?
Reply with quote

Quote:

Using ms sql 2000 and VS2003

I need a little addition to my application that already gets a bunch of
records from a database.
Each row has two dates from two different tables, and an ID column so
the return set looks like this:

ID DateLastModified DateLastSent
1 12/12/05 time 12/15/05
2 9/8/06 9/1/06

What I need to do is compare the two dates in any row and be able to
have an event fire if and only if the date in the DateLastSent column
is smaller (occured before) the date in DateLastModified. I think I
could get as far as getting the two dates but I have no idea how to
compare the datetimes in C#. My other problem is that I'm not sure how
I would be able to check every row and select the ID of those that meet
my condition.

Why do it in C#, when you can do it in your database instead?


convert( varchar(10), YourDate, 101 ) as YourDate,



 

Back to top
View user's profile Send private message
Author
BradleyPeter
Beginner
Joined: 11 Jul 2006
Posts: 150

PostPosted: Tue Jul 25, 2006 1:00 am    
Post subject:
Reply with quote
Well, as I often do, I could be missing something, but I don't see where the comparison is in that solution. I agree with doing the job in SQL though; preferably in a stored procedure.

What I was going to suggest was to create an extra column via the sql query along the lines of:

SELECT ID,
DATE_LAST_MODIFIED,
DATE_LAST_SENT,
CASE WHEN DATE_LAST_SENT > DATE_LAST_MODIFIED
THEN 1
ELSE 0
END AS IS_GREATER FROM MY TABLE etc

There's probably a need for more info on what event is supposed to be fired, though; and when and how.

My apologies, Steve, if I've got the wrong end of the stick. Again.

:)


Peter



-----Original Message-----
From: DotNetDevelopment on behalf of srussell Sent: Mon 7/24/2006 8:29 PM To: DotNetDevelopment Cc:
Subject: [DotNetDevelopment] Re: How do I compare dates in ms sql tables in C#?


Quote:

Using ms sql 2000 and VS2003

I need a little addition to my application that already gets a bunch of
records from a database.
Each row has two dates from two different tables, and an ID column so
the return set looks like this:

ID DateLastModified DateLastSent
1 12/12/05 time 12/15/05
2 9/8/06 9/1/06

What I need to do is compare the two dates in any row and be able to
have an event fire if and only if the date in the DateLastSent column
is smaller (occured before) the date in DateLastModified. I think I
could get as far as getting the two dates but I have no idea how to
compare the datetimes in C#. My other problem is that I'm not sure how
I would be able to check every row and select the ID of those that meet
my condition.

Why do it in C#, when you can do it in your database instead?


convert( varchar(10), YourDate, 101 ) as YourDate,









 

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    MasterVB.NET Forum Index -> Database Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Archieve

Powered by phpBB © 2001, 2002 phpBB Group, used in Visual Basic 2005 .NET Forum

| Visual Basic .NET Forum | Online Recipe Archiver | Shareware Freeware PAD | Lowongan Kerja | Kamus Online | Health Supply | Digital Camera Review |
Orang Paling Keren

RSS