If todays date is the 3rd of the month then

papasmurfuo9

Registered User.
Local time
Today, 04:21
Joined
May 28, 2014
Messages
69
hi
could someone get me started on the below please

If todays date is the 3rd of the month then
Msgbox “hi”
Else
Msgbox “bye”
End if

thank you
 
hi
could someone get me started on the below please

If todays date is the 3rd of the month then
Msgbox “hi”
Else
Msgbox “bye”
End if

thank you

if day(now())=3 then
 
surely datepart

if (DatePart("d", Date))<=3 then
etc
 
Yes I wasn't thinking straight. :)

I'd use Date() in place of Now()
Why?

I've just done a quick and dirty test. Date() takes 53 seconds while now() takes 51 seconds when in a 100,000,000 iteration loop.

The meaning of now() is pretty unequivocal if you use multiple programming languages.
 
Interesting test Gorf! I did the same test and got 29 and 31 secs. My guess is that Date() is slower because it's an extract from date/time (like you have in MySQL).

gemma-the-husky will be pleased to know that DatePart() took almost 2 minutes ;)
 
Interesting test Gorf! I did the same test and got 29 and 31 secs. ...
Your wife is obviously nicer than mine and allows you to have a quad core. :D

I ran the test again - there was still a two-second gap between Date() and Now() but they were both two seconds quicker than my earlier test.

There's just so much going on "under the hood" on a Windows PC, it's not possible to get a definitive answer to which one is faster because the test results aren't consistent, and it's hardly relevant if you have to look to 100,000,000 iterations before you see a measurable difference between the two. I'd still be interested to know why you think (or thought) Date() is better programming practice than Now()

Code:
Private Sub test()
   Dim a1 As Date, a2 As Date, a3 As Date
   Dim g As Integer, i As Long

   a1 = Now
   For i = 1 To 100000000
     g = Day(Now())
   Next i
   a2 = Now

  For i = 1 To 100000000
    g = Day(Date)
  Next i
  a3 = Now

  MsgBox a1 & Chr(13) & a2 & Chr(13) & a3

End Sub
 
I'd still be interested to know why you think (or thought) Date() is better programming practice than Now()
I like to use what is relevant where possible. For example if you were using Now() as criteria in a query, the Time part will give problems, not that it will matter in the Day() function anyway.
 

Users who are viewing this thread

Back
Top Bottom