Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting yesterday's date

Status
Not open for further replies.

ProBani

Programmer
Mar 21, 2005
48
YU
Hello there,

in vb.net (it is actually web application) I would like to perform condition based on if actual selected date by user is yeserday's date or no? this the code :
-------------------------------------------------------
Dim date1 As New Date
date1 = Request.QueryString.Get("ndate")

Try
Dim objConn As New SqlConnection(strConn)
If date1.Day = (Now.Day - 1) Then
cmd = New SqlCommand( _
"SELECT l.activityID,r.ac_name,r.description FROM users_activity L INNER JOIN tblactivities R ON l.activityID=r.activityID WHERE l.Userid='" _
& Session("user") & "'" _
& " ORDER BY L.activityID", objConn)
Else
cmd = New SqlCommand( _
"SELECT l.activityID,r.ac_name,r.description FROM users_activity L INNER JOIN tblactivities R ON l.activityID=r.activityID WHERE l.Userid='" _
& Session("user") & "'" & " AND l.activityID IN (SELECT ID FROM GeneralActivities)" _
& " ORDER BY L.activityID", objConn)
End If

............. ----------------------------------------

The whole point is here If date1.Day = (Now.Day - 1) that is giving me for today's case result "0" - I mean simply I can't compare the date1 (which is selected date by user) with the yesterday date.

Regards,
Probani.
 
Well this is the VB6 forum.

Try here for VB.Not: forum796


The VB6 answer is: Yesterday = DateAdd("d", -1, Date)
 
I second Sheco in pointing you to the correct forum. In VB6 you could also use:

Yesterday = Date - 1

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
AND for vb.net DateTime.Today.AddDays(-1)

i just discover!

Thnx,
Probani.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top