By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,594 Members | 2,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,594 IT Pros & Developers. It's quick & easy.

How to test whether date is today

lee123
100+
P: 556
how do i change this code to do dates instead if time:

Expand|Select|Wrap|Line Numbers
  1.   CurrentTime = Format(Time, "hh:mm")
  2.     If CurrentTime = txtBillTime.Text Then
  3.         Beep
  4.         frmAppointment.WindowState = 0 'Restore form
  5.     End If
lee123
Dec 26 '07 #1
Share this Question
Share on Google+
19 Replies


VijaySofist
100+
P: 107
Hi!

I think this is the one you looked for

Code: ( text )

1. CurrentDate = Format(Date, "dd-MM-yyyy")
2. If CurrentDate = Format(txtBillDate.Text,"dd-MM-yyyy") Then
3. Beep
4. frmAppointment.WindowState = 0 'Restore form
5. End If


If the above is not the code you looked for means, Can you please explain clearly.


All the Best

With Regards
Vijay. R
Dec 26 '07 #2

debasisdas
Expert 5K+
P: 8,127
If you want date why passing time ?

Instead of passing time ,you need to pass date.
Dec 26 '07 #3

lee123
100+
P: 556
Debasisdas,
i stumbled on to this code for a project im doing. and the way they did this it only had time. but i wanted something with dates. so when that date hit it would pop up the form (a reminder)

thanks vijaysofist i'll try this and see if it works.

lee123
Dec 26 '07 #4

lee123
100+
P: 556
hey vijaysofist,

i found this code in a book i have because it deals with something i've been trying to do but it only has the time i wanted it for the date. so i can set it and when the date hit it would pop up the message i typed in the form like a reminder the whole code to this is:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSetTime_Click()    
  2.     frmAppointment.WindowState = 1  ('this is to set the form to close to the task bar)
  3.     Timer1.Enabled = True  
  4. End Sub
then in the timer i have this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Timer1_Timer()
  2.     On Error Resume Next
  3.    CurrentDate = Format(Date, "mm-dd-yy")
  4.     If CurrentDate = Format(Txtbilldate, "mm-dd-yy") Then
  5.         Beep
  6.         frmAppointment.WindowState = 0 'Restore form
  7.     End If
  8. End Sub
I wanted this code to do dates so i can enter in a date so when the date came it would remind me of a task or appointment. but i tried your code and the form doesn't close to the taskbar it keeps popping back up when i try to set the date


lee123
Dec 26 '07 #5

lee123
100+
P: 556
i have posted a reply but it never shows up
Dec 26 '07 #6

lee123
100+
P: 556
hi there i have been posting posts but they don't show up anyway

to vijaysofist,

i have tried your code but it doesn't work the whole code i have in my form is this. in the button to (set the date):
Expand|Select|Wrap|Line Numbers
  1. Private Sub SetDate_Click()
  2.     On Error Resume Next
  3.     frmAppointment.WindowState = 1
  4.     Timer1.Enabled = True  'Start timer
  5. End Sub
and for the timer i have this now.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Timer1_Timer()
  2.     On Error Resume Next
  3.    CurrentDate = Format(Date, "mm/dd/yy")
  4.     If CurrentDate = Format(Txtbilldate, "MM/DD/YY") Then
  5.         Beep
  6.         Timer1.Enabled = False
  7.         frmAppointment.WindowState = 0 'Restore form
  8.     End If
  9. End Sub
  10.  
but the whole thing is suppose to be a (reminder form) that pops up when you set the date you want to be reminded of a task or appointment. but i can't get it to work right.

to debasisdas:

to answer your question i found this code in a book i have but it deals with the time only and it's similar to what i wanted to do but with dates i wanted to use this code for the project above. by the way what did you mean by this:


Expand|Select|Wrap|Line Numbers
  1. If you want date why passing time ?
  2.  
  3. Instead of passing time ,you need to pass date.
lee123
Dec 27 '07 #7

VijaySofist
100+
P: 107
hey vijaysofist,

i found this code in a book i have because it deals with something i've been trying to do but it only has the time i wanted it for the date. so i can set it and when the date hit it would pop up the message i typed in the form like a reminder the whole code to this is:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSetTime_Click()    
  2.     frmAppointment.WindowState = 1  ('this is to set the form to close to the task bar)
  3.     Timer1.Enabled = True  
  4. End Sub
then in the timer i have this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Timer1_Timer()
  2.     On Error Resume Next
  3.    CurrentDate = Format(Date, "mm-dd-yy")
  4.     If CurrentDate = Format(Txtbilldate, "mm-dd-yy") Then
  5.         Beep
  6.         frmAppointment.WindowState = 0 'Restore form
  7.     End If
  8. End Sub
I wanted this code to do dates so i can enter in a date so when the date came it would remind me of a task or appointment. but i tried your code and the form doesn't close to the taskbar it keeps popping back up when i try to set the date


lee123


Hi!

So you want your form to close to the taskbar! Right.

Please Look back your code. This is because in the cmdSetTime_Click() Event - you minimized the Form and then Enabled the Timer - where the timer maximizes the form again.

Use
---------------
frmAppointment.WindowState = 0 'in the cmdSetTime_Click() Event

and Use
--------------
frmAppointment.WindowState = 1 'in the Timer1_Timer() Event

Please get back to me, whether it works for you or not.


All the Best

With Regards
Vijay. R
Dec 27 '07 #8

VijaySofist
100+
P: 107
Hi!

Check whether if you are using a text box named Txtbilldate to get the date.

Check it and reply My Friend!


With Regards
Vijay. R
Dec 27 '07 #9

9815402440
100+
P: 180
hi
replace line
If CurrentDate = Format(Txtbilldate, "MM/DD/YY") Then
with following line

If datediff("d",format(CurrentDate,"mm/dd/yy") , Format(Txtbilldate, "MM/DD/YY"))=0 Then

because using CurrentDate = Format(Txtbilldate, "MM/DD/YY") you are comparing two strings not two dates.

regards
manpreet singh dhillon hoshiarpur
Dec 27 '07 #10

debasisdas
Expert 5K+
P: 8,127
Let me know do you still have the problem.

Do not start another thread just to reply to another .

Please continue in the same thread only.

Both tthe threads are merged for better management of the forum.
Dec 27 '07 #11

daniel aristidou
100+
P: 491
hi
replace line
If CurrentDate = Format(Txtbilldate, "MM/DD/YY") Then
with following line

If datediff("d",format(CurrentDate,"mm/dd/yy") , Format(Txtbilldate, "MM/DD/YY"))=0 Then

because using CurrentDate = Format(Txtbilldate, "MM/DD/YY") you are comparing two strings not two dates.
You can also try the Cdate method
ie
Expand|Select|Wrap|Line Numbers
  1. if Cdate(date) = Cdate(Txtbilldate) then
ect
The reson other attemps did not work is because you comparing
dates such as 12/1/2007 with 3/3/2008

12/#/#### is greater than 3/#/###
What you should of done is

Formatdate(txtbilldate,"YYYYMMDD")
Dec 27 '07 #12

lee123
100+
P: 556
do i still set the timer intervals at 1000?

lee123
Dec 28 '07 #13

lee123
100+
P: 556
hey thanks it worked but as soon as it hits 12:00 am it beeps. but i was thinking who's up at that time? i thank you guys for all your help. but me not thinking of the problem at hand there's got to be a way to set a time too.

example: 12/28/07 @ 8:00am or something like that. i think i might have to put another textbox on the form for this. right? and use the same code but with the time. or can i merge the code in the code now?

lee123
Dec 28 '07 #14

daniel aristidou
100+
P: 491
hey thanks it worked but as soon as it hits 12:00 am it beeps. but i was thinking who's up at that time? i thank you guys for all your help. but me not thinking of the problem at hand there's got to be a way to set a time too.

example: 12/28/07 @ 8:00am or something like that. i think i might have to put another textbox on the form for this. right? and use the same code but with the time. or can i merge the code in the code now?

lee123
use "now" instead of date and use it like this

Note that the case of the letters is important
Expand|Select|Wrap|Line Numbers
  1. if format(Now,"yyyymmddhhMMss") = Format(txtbilldate,"yyyymmddhhMMss")
Also note that you have to type the date and time in the textbox correct or else it will create an error or will simply not format the date and time entered

Enter the time and date in the textbox like this
"28/12/2007 10:42:13"

Also if you dont want to be as precise as seconds change the format to this:
Expand|Select|Wrap|Line Numbers
  1. if format(Now,"yyyymmddhhMM") = Format(txtbilldate,"yyyymmddhhMM")
(note i simply removed the "ss"
If you are gonna use this way you can also enter the date and time in the text box like this "28/12/2007 10:42"

Regards Daniel
Dec 28 '07 #15

lee123
100+
P: 556
hey thanks daniel it worked are again thanks to all of you other ones that help out too.


lee123
Dec 28 '07 #16

lee123
100+
P: 556
Hey there is there a way to make this form pop up when starting up windows i mean if you have a date and time and a reminder in the textboxes that aren't due for a few days?

lee123
Dec 29 '07 #17

daniel aristidou
100+
P: 491
Hey there is there a way to make this form pop up when starting up windows i mean if you have a date and time and a reminder in the textboxes that aren't due for a few days?

lee123
Although there are many ways, and most will tell you to use the windows registry. I advise you to use the windows startup folder since it offers more control.

Since i dont know what kind of program this is it varies on the way i would go about this.

If you want the program to load every time the computer starts up- simply create a shortcut in the windows startup folder(should be located inside the startmenu)
If not i might suggest that you place code inside you form which is something like this when the form loads.
Expand|Select|Wrap|Line Numbers
  1. if not textboxdate = Date then
  2. unload me
  3. End if
There is another way i can think of but rather complicated......let me know if this is what you want. if it isnt ill post the other method using the startup folder.

Using the registry would make things alot more complicated.
Another method occured to me using system service but coding it is beyond me. so i would will post the idea for someoneelse to help figure out if it comes to that. :-)
(+_+)
Regards Daniel
Dec 29 '07 #18

lee123
100+
P: 556
well the application i have made is a reminder. lets say you wanted a reminder of a certain date you had to do something then you would enter in the date and time and then when that date and time came the reminder program would pop up but right now it only works if you run the program and go to the (reminder) i have a database in the background saving the time and date in the database so it doesn't erase when you stop the program. if i was to distribute this program to someone else or they bought this from me and they liked the program they would probably want the form to load when they started windows. i mean if they had a date and time already in it.you know? and not have to run the program.( oh just so you know this form, is part of another form i created) but whats the use of this form if you had to run the program evertime. i didn't think this would be so useful especially if you had a million things to do. but it goes with the other forms.

lee123
Dec 29 '07 #19

daniel aristidou
100+
P: 491
lets say you wanted a reminder of a certain date you had to do something then you would enter in the date and time and then when that date and time came the reminder program would pop up but right now it only works if you run the program and go to the (reminder) i have a database in the background saving the time and date in the database so it doesn't erase when you stop the program. if i was to distribute this program to someone else or they bought this from me and they liked the program they would probably want the form to load when they started windows. i mean if they had a date and time already in it.you know? and not have to run the program.( oh just so you know this form, is part of another form i created) lee123
OK ...
2 options either a service. or your program will load with no forms visible on windows startup.
The idea is for windows to load and then if the date and time is passed the form to appear.......Correct? Changing it into a service is beyond me...so im sure someone else can help out if thisdoes not work.I believe this way will work though.(~_~)
This is what you do. you copy the program to startup folder.
In vb you add this on the forms for when they load
Expand|Select|Wrap|Line Numbers
  1. private sub Form_Load
  2. Form.visible = False
  3. End sub
However i suggest that you change the code you had previously so that instead of :
Expand|Select|Wrap|Line Numbers
  1. If XXXX=XXXXX then 
You changed it to
Expand|Select|Wrap|Line Numbers
  1. If format(now,"yyyymmddhhMM") >= format(XXXXX,"yyyymmddhhMM") then
  2. <Your form>.Show (1)
This will have to be done due to the fact that you maystartup you computer after the date has passed.
I can see a bug in this though. Question do you have a command button on the message form which shuts the program?
If not i suggest you do.This will stop the message form being made modal over and over again.
Daniel (~_~) Happy new year
Dec 31 '07 #20

Post your reply

Sign in to post your reply or Sign up for a free account.