How to test whether date is today

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lee123
    Contributor
    • Feb 2007
    • 556

    How to test whether date is today

    how do i change this code to do dates instead if time:

    Code:
      CurrentTime = Format(Time, "hh:mm")
        If CurrentTime = txtBillTime.Text Then
            Beep
            frmAppointment.WindowState = 0 'Restore form
        End If
    lee123
  • VijaySofist
    New Member
    • Jun 2007
    • 107

    #2
    Hi!

    I think this is the one you looked for

    Code: ( text )

    1. CurrentDate = Format(Date, "dd-MM-yyyy")
    2. If CurrentDate = Format(txtBillD ate.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

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      If you want date why passing time ?

      Instead of passing time ,you need to pass date.

      Comment

      • lee123
        Contributor
        • Feb 2007
        • 556

        #4
        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

        Comment

        • lee123
          Contributor
          • Feb 2007
          • 556

          #5
          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:
          Code:
          Private Sub cmdSetTime_Click()    
              frmAppointment.WindowState = 1  ('this is to set the form to close to the task bar)
              Timer1.Enabled = True  
          End Sub
          then in the timer i have this:

          Code:
          Private Sub Timer1_Timer()
              On Error Resume Next
             CurrentDate = Format(Date, "mm-dd-yy")
              If CurrentDate = Format(Txtbilldate, "mm-dd-yy") Then
                  Beep
                  frmAppointment.WindowState = 0 'Restore form
              End If
          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

          Comment

          • lee123
            Contributor
            • Feb 2007
            • 556

            #6
            i have posted a reply but it never shows up

            Comment

            • lee123
              Contributor
              • Feb 2007
              • 556

              #7
              RE-change this to date

              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):
              [code=vb]
              Private Sub SetDate_Click()
              On Error Resume Next
              frmAppointment. WindowState = 1
              Timer1.Enabled = True 'Start timer
              End Sub[/code]

              and for the timer i have this now.
              [code=vb]
              Private Sub Timer1_Timer()
              On Error Resume Next
              CurrentDate = Format(Date, "mm/dd/yy")
              If CurrentDate = Format(Txtbilld ate, "MM/DD/YY") Then
              Beep
              Timer1.Enabled = False
              frmAppointment. WindowState = 0 'Restore form
              End If
              End Sub
              [/code]
              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:


              Code:
              If you want date why passing time ?
              
              Instead of passing time ,you need to pass date.
              lee123
              Last edited by debasisdas; Dec 27 '07, 11:01 AM. Reason: Formatted using code=vb tags

              Comment

              • VijaySofist
                New Member
                • Jun 2007
                • 107

                #8
                Originally posted by lee123
                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:
                Code:
                Private Sub cmdSetTime_Click()    
                    frmAppointment.WindowState = 1  ('this is to set the form to close to the task bar)
                    Timer1.Enabled = True  
                End Sub
                then in the timer i have this:

                Code:
                Private Sub Timer1_Timer()
                    On Error Resume Next
                   CurrentDate = Format(Date, "mm-dd-yy")
                    If CurrentDate = Format(Txtbilldate, "mm-dd-yy") Then
                        Beep
                        frmAppointment.WindowState = 0 'Restore form
                    End If
                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_Clic k() Event - you minimized the Form and then Enabled the Timer - where the timer maximizes the form again.

                Use
                ---------------
                frmAppointment. WindowState = 0 'in the cmdSetTime_Clic k() 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

                Comment

                • VijaySofist
                  New Member
                  • Jun 2007
                  • 107

                  #9
                  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

                  Comment

                  • 9815402440
                    New Member
                    • Oct 2007
                    • 180

                    #10
                    hi
                    replace line
                    If CurrentDate = Format(Txtbilld ate, "MM/DD/YY") Then
                    with following line

                    If datediff("d",fo rmat(CurrentDat e,"mm/dd/yy") , Format(Txtbilld ate, "MM/DD/YY"))=0 Then

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

                    regards
                    manpreet singh dhillon hoshiarpur

                    Comment

                    • debasisdas
                      Recognized Expert Expert
                      • Dec 2006
                      • 8119

                      #11
                      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.

                      Comment

                      • daniel aristidou
                        Contributor
                        • Aug 2007
                        • 494

                        #12
                        Originally posted by 9815402440
                        hi
                        replace line
                        If CurrentDate = Format(Txtbilld ate, "MM/DD/YY") Then
                        with following line

                        If datediff("d",fo rmat(CurrentDat e,"mm/dd/yy") , Format(Txtbilld ate, "MM/DD/YY"))=0 Then

                        because using CurrentDate = Format(Txtbilld ate, "MM/DD/YY") you are comparing two strings not two dates.
                        You can also try the Cdate method
                        ie
                        Code:
                        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(txtb illdate,"YYYYMM DD")

                        Comment

                        • lee123
                          Contributor
                          • Feb 2007
                          • 556

                          #13
                          do i still set the timer intervals at 1000?

                          lee123

                          Comment

                          • lee123
                            Contributor
                            • Feb 2007
                            • 556

                            #14
                            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

                            Comment

                            • daniel aristidou
                              Contributor
                              • Aug 2007
                              • 494

                              #15
                              Originally posted by lee123
                              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
                              Code:
                              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:
                              Code:
                              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

                              Comment

                              Working...