Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 9th, 2009, 01:00 AM
Authorized User
 
Join Date: Oct 2009
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
Default Date time compare

Hi All,

I’m a bit stuck I want to compare my last transaction date / time which display in a label ‘that I get from the data base’ to the system date / time and if there is a deference of 5 minutes then I get a massage.
I have played around and I do get a massage when the last transaction date is smaller but it doesn’t look for a 5 minute deference even if I use a timer.

Help will be much appreciated’
This is what I’ve got but it’s not doing what I expected

Code:
Private Sub Command1_Click()
Dim date1 As Date
Dim label1 As Date
    
date1 = Format(Now, "yyyy/mm/dd hh:mm:ss")
date2 = label1
If DateDiff("n", Now, date1) > DateDiff("n", Now, label1) Then
   MsgBox ("Not Vending")
 End If
End Sub
I try this no luck

Code:
Private Sub Command1_Click()

If DateDiff("n", Now, label1) > 5 Then
   MsgBox ("Not Vending")
 End If
End Sub
And this no luck

Code:
Private Sub Command1_Click()
Dim date1 As Date
date1 = label1
If DateDiff("n", Now, label1) < 5 Then
   MsgBox ("Not Vending")
 End If
End Sub
New to date time functions and cant seem to get it right

Last edited by Janos; December 9th, 2009 at 01:05 AM..
 
Old December 9th, 2009, 07:32 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Can you check if the following works

Code:
Dim date1 As Date
Dim date2 As Date
Dim label1
    
date1 = Format(Now, "yyyy/mm/dd hh:mm:ss")
date2 = Format(label1, "yyyy/mm/dd hh:mm:ss")
If DateDiff("n", date1, date2) > 5 Then
   MsgBox ("Not Vending")
 End If
End Sub
Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips &amp; Tricks (http://www.vbadud.blogspot.com)
 
Old December 9th, 2009, 09:01 AM
Authorized User
 
Join Date: Oct 2009
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thanks for the replay still not working, I was wondering my system date time displays in a label is it possible to compare the two labels with each other and if the label with the transaction date time in it is 5 mins smaller than the system date time then I get a massage,, do not now ?
 
Old December 9th, 2009, 10:01 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

You Can try the following

Code:
Dim date1 As Date
Dim date2 As Date
    
date1 = Format(label1.Caption, "yyyy/mm/dd hh:mm:ss")
date2 = Format(label2.Caption, "yyyy/mm/dd hh:mm:ss")
If DateDiff("n", date1, date2) > 5 Then
   MsgBox ("Not Vending")
 End If
End Sub

or

Code:
Dim date1 As Date
Dim date2 As Date
    
date1 = Format(label1.Caption, "yyyy/mm/dd hh:mm:ss")
date2 = Format(Now(), "yyyy/mm/dd hh:mm:ss")
If DateDiff("n", date1, date2) > 5 Then
   MsgBox ("Not Vending")
End If
End Sub

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips &amp; Tricks (http://www.vbadud.blogspot.com)
 
Old December 11th, 2009, 12:52 AM
Authorized User
 
Join Date: Oct 2009
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thanks for the afford Shasur your code snippets does work but it still doesn’t look for a 5 minute deferens. I well get it sooner or later having a hard time grasping these date time functions.
 
Old December 11th, 2009, 06:09 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

I am afraid if the label text is converted as date?

You can check that by IsDate function

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips &amp; Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare date in XPath Expression extkml XSLT 1 November 4th, 2009 06:53 AM
Want jsp code to compare start date and end date rajeshree13 Java Basics 2 July 20th, 2009 03:10 AM
compare these date fields and compare and get the susanring Oracle 1 July 24th, 2006 04:58 PM
Compare time in SQL JaJa SQL Language 2 October 21st, 2004 05:42 PM
Alarm Clock/How to Compare Set TIme mjwelker VB How-To 2 May 5th, 2004 05:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.