Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • Last Modified:

Execute code on specific day

The code below executes the 9th of each month.  I would like to change the following vb6 code to execute when it is only July 9,2013.

currentservertime already contains the current date.  

How do I do that?

If Day(currentServerTime) < 9 Then
                    'Add code here
            End If

Open in new window

0
al4629740
Asked:
al4629740
  • 2
  • 2
1 Solution
 
FaustulusCommented:
How about this?
If Date = DateSerial(2013,7,9) Then
    ' add your code here
End If

Open in new window

You can expand on the idea like this:-
If Now > (DateSerial(2013,7,9) + TimeSerial(12,0,0)) Then
    ' add your code here
End If

Open in new window

This would run any time after 12 pm on July 9. Your code could include a line to abort if the time window you want to allow is exceeded.
Basically, if you wish a program to run on July 9, 2013 you would need to set a timer which would wake up the computer and run the program when the time has arrived. This is what they use for automatic backups. The above kind of code would need to be called by the user or, perhaps a startup procedure, and then refuse to run at any other time. But it could be run multiple times within the prescribed time frame unless your code includes provision to allow it to run only once.
0
 
al4629740Author Commented:
Can I do
July 9, 2013. 8:00pm
0
 
al4629740Author Commented:
This didn't work.  Do I have the format wrong

If Date = DateSerial(2013,7,9) Then
    ' add your code here
End If
0
 
FaustulusCommented:
TimeSerial(20,0,0) would define 8 pm. The parameters are Hour, Minute, Second - all counting from 00:00 h military time.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now