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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Trouble!

Status
Not open for further replies.

LucyL

Technical User
Feb 20, 2002
113
0
0
US
Hi,
I need to do a few things in the one query and am not sure how the syntax goes...

heres what I want to do...
I have three dates
Lastdate, Now() and New Date.
- I want to cut the MM from LastDate - Left$(LastDate,2)
- Now I want to sub in this MM for the MM in todays date.
- And finally I want to test whether this new date (todays with the MM substituted in) is greater than todays date.

Is there a way of doing all this in the one query?
Thank you!
 
This is totally untested pseudo code. You mentioned that you wanted this in one "query." So, my code may not be applicable since it would be a Sub Procedure. Not sure if you were wanted to do this in a database query.

Dim myMonth As String
Dim myDay As String
Dim myDate As String

myMonth = Left$(LastDate,2)
myDay = Mid$(Now,4,5)
myDate = myMonth & "/" & myDay

If CDate(myDate) > Format$(Now, "mm/dd") Then
'do something
End If

 
Hi,
U can construct a date using the month of now() (by using month() fn), day() fn of lastdate() and year() fn of lastdate().
Then compare this newdate with today's date(using Date() fn).
All these can be done in one query, I am not sure what is the fn used to construct a date.Should u use format fn?
One suggestion, try avoiding use left, right fns etc in dates unless u r sure of the formats ie. the date will be in "mm/dd/yyyy" format etc, then u can use left() fn etc.
Hope this helps. Goodluck!


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top