Link to home
Start Free TrialLog in
Avatar of isnoend2001
isnoend2001Flag for United States of America

asked on

Working with datepicker values vb6

i am trying to this, but it does not work
If mydate > Now Then'this does not work
'start tomorrow
'MsgBox "Notifactions will start tomorrow," WeekdayName & Format(DTPicker1.Value, "HH:MM AM/PM") & " and continue everyday"
'Else
'start today
MsgBox "Reminder will notify at " & Format(DTPicker1.Value, "HH:MM AM/PM") & " Today and continue everyday" '12 hr time"
End If
the date picker value to test with
Debug.Print DTPicker1.Value produces this: 10/3/2015 7:00:00 PM
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

I don't know what you have in mydate, but if I set it to Now - 1 or Now + 1 it worked (with the changes below).
If mydate > Now Then
    'start tomorrow
    MsgBox "Notifications will start tomorrow, " & Format(DateAdd("d", 1, Now), "dddd") & ", at " _
          & Format(DTPicker1.Value, "HH:MM AM/PM") & " and will continue everyday"
Else
    'start today
    MsgBox "Reminder will appear at " & Format(DTPicker1.Value, "HH:MM AM/PM") & " today and will continue everyday" '12 hr time"
End If

Open in new window

Avatar of isnoend2001

ASKER

Debug.Print DTPicker1.Value produces this: 10/3/2015 7:00:00 PM
mydate = DTPicker1.Value
i willtest your code
no matter what time i select it only does the else
MsgBox "Reminder will appear at " & Format(DTPicker1.Value, "HH:MM AM/PM") & " today and will continue everyday" '12 hr time"
example
User generated image
What is in mydate?
Private Sub Command_Click()
Dim mydate As Date
I meant - what is the value when the code runs?
here is everything
Private Sub Command_Click()
Dim mydate As Date
Dim myDay As Integer
'  Dim fName As String
   mydate = DTPicker1.Value
    If mydate > Now Then
    'start tomorrow
    MsgBox "Notifications will start tomorrow, " & Format(DateAdd("d", 1, Now), "dddd") & ", at " _
          & Format(DTPicker1.Value, "HH:MM AM/PM") & " and will continue everyday"
Else
    'start today
    MsgBox "Reminder will appear at " & Format(DTPicker1.Value, "HH:MM AM/PM") & " today and will continue everyday" '12 hr time"
End If
also
   the tomorrow date need to add 1 day to the date
Did you actually choose 10/17? I did and it works for me with this code (you don't need mydate; you can always use the vales of controls directly).

Private Sub Command1_Click()

If DTPicker1.Value > Now Then
    'start tomorrow
    MsgBox "Notifications will start tomorrow, " & Format(DateAdd("d", 1, Now), "dddd") & ", at " _
          & Format(DTPicker1.Value, "HH:MM AM/PM") & " and will continue everyday"
Else
    'start today
    MsgBox "Reminder will appear at " & Format(DTPicker1.Value, "HH:MM AM/PM") & " today and will continue everyday" '12 hr time"
End If
End Sub

Open in new window

However if you choose a date after tomorrow, the message will still say "tomorrow". what do you want it to say?
Oh I see! You have time in the datepicker. Let me try that and see what I can do.
ok
This works but there's a problem I think.
Private Sub Command1_Click()

If DateDiff("h", DTPicker1.Value, Now) > 1 Then
    'start tomorrow
    MsgBox "Notifications will start tomorrow, " & Format(DateAdd("d", 1, Now), "dddd") & ", at " _
          & Format(DTPicker1.Value, "HH:MM AM/PM") & " and will continue everyday"
Else
    'start today
    MsgBox "Reminder will appear at " & Format(DTPicker1.Value, "HH:MM AM/PM") & " today and will continue everyday" '12 hr time"
End If
End Sub

Open in new window

The problem is this. Let's say it's 7:19 PM here (which it is) if I use the up button on the dtpicker to get to, say, 10PM I get the "tomorrow" message. If however I use the down button until it shows 10PM I get the "today" message.
yes there is something wrong
time now 7:52
datepicker time 10:00pm
message says tomorrow, but it should say today
As I said, you can get to 10PM by going up or down. If you sister chooses 10PM, no matter which way she gets there, do you always want to say "tomorrow"?
If so change the first line to

If Format(DTPicker1.Value, "HH:MM") > Format(Now, "HH:MM") Then

Open in new window


Note: Don't add the "AM/PM" to that line.
No if the datepicker time is later than the pc time the it should say today
Then change the > to a <.
something is wrong
User generated image
With this code
User generated imagewhere the dtpicker time is less than the PC time (10:19 PM) I get this
User generated imageand when the dtpicker time is greater I get this
 User generated image
Yes it's backwards
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Could you post the code instead of a image of the code ?
Thanks marty got it, never  relized dates/times was so difficult