 |

11-14-2005, 03:01 PM
|
|
Regular
|
|
Join Date: Oct 2005
Posts: 65
|
|
Formatting Data for Time
|
I have built an application to report my backup times on our servers. I have not formatted time before and am not sure how to display it.
I have declared my variables as Date and used the dte prefix on my date controls. (I know that it is just for my use.) but when I display the total in a label I am getting the date shown as mm/dd/yy. I need it shown in hours and minutes.
Here is an example of my code.
lblServerNameTotal.Caption = Format?(dteServerNameTotal)
Replace the ? for the format I need to use.
I know this is a breeze for you all but your help is greatly appreciated.
Thanks
|
|

11-14-2005, 03:20 PM
|
 |
Martian In Disguise
Retired Moderator * Guru *
|
|
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
|
|
Code:
lblServerNameTotal.Caption = Format$(dteServerNameTotal, "mm/dd/yyyy hh:nn")
|
__________________
The only stupid question is the one that goes un-asked.
|

11-17-2005, 09:23 AM
|
|
Regular
|
|
Join Date: Oct 2005
Posts: 65
|
|
|
I am still not able to get the time to display correctly. It is coming up 00:00.
Here is the code I have...
'Declare local level variables
Dim dteInfonet As Date
Dim dteInfonetStart As Date
Dim dteInfonetTotal As Date
'Convert input values as numeric values
dteInfonet = Val(txtInfonet.Text)
'Calculate Totals
dteInfonetTotal = dteInfonet - dteInfonetStart
'Display Totals in labels
lblInfonetTotal.Caption = Format$(dteInfonetTotal, "hh:mm")
What it looks like is
Server Backup Start Time Backup End Time Time needed for Backup
(dteInfonetStart) (dteInfonet) (dteInfonetTotal)
(lblInfonetStart.Caption) (txt.Infonet.Text) (lblInfonetTotal.Caption)
Infonet 22:30 22:35 00:00
The time needed for backup should be 00:05 but it is not.
Any ideas?
|
|

11-17-2005, 09:26 AM
|
 |
Web Junkie
Retired Moderator * Expert *
|
|
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
|
|
|
The problem is probably when you calculate the Difference. You should be using the DateDiff() function instead of just using subtraction.
|
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
|

11-17-2005, 11:48 AM
|
|
Regular
|
|
Join Date: Oct 2005
Posts: 65
|
|
|
I am not 100% use I understand where to use "DateDiff"
'Calculate Totals
dteInfonetTotal = dteInfonet - dteInfonetStart
dteInfonetTotal = dteInfonet DateDiff dteInfonetStart
or is it...
lblInfonetTotal.Caption = DateDiff(dteInfonetTotal, "hh:mm")
or am I wrong on both accounts?
|
|

11-17-2005, 11:55 AM
|
 |
Ultimate Contributor
Retired Leader * Guru *
|
|
Join Date: Aug 2001
Posts: 5,343
|
|
You're close, but DateDiff doesn't work that way. You need to specify two dates and an interval in the DateDiff() function. The interval refers to the type of quantity you want measured between the dates: days, weeks, months, etc.
Something like this should work:
Code:
Dim mins As Long
Dim totalTime As String
mins = DateDiff("m", dteInfonetStart, dteInfonet)
totalTime = Format$(CLng(mins / 60) & ":" & mins Mod 60, "hh:mm")
|
|

11-17-2005, 12:07 PM
|
|
Regular
|
|
Join Date: Oct 2005
Posts: 65
|
|
|
I declared...
Dim mins As Long
Dim totalTime As String
to my local variables
and added
'Display Totals in labels
lblInfonetTotal.Caption = Format$(dteInfonetTotal, "hh:mm")
mins = DateDiff("m", dteInfonetStart, dteInfonet)
totalTime = Format$(CLng(mins / 60) & ":" & mins Mod 60, "hh:mm")
and recieved 00:00 again.
I removed the
Format$(dteInfonetTotal, "hh:mm") and made it ...
Display Totals in labels
lblInfonetTotal.Caption = mins = DateDiff("m", dteInfonetStart, dteInfonet)
totalTime = Format$(CLng(mins / 60) & ":" & mins Mod 60, "hh:mm")
and recieved "False" in my label
I tried...
'Display Totals in labels
mins = DateDiff("m", dteInfonetStart, dteInfonet)
totalTime = Format$(CLng(mins / 60) & ":" & mins Mod 60, "hh:mm")
and recieved a blank in my label.
Save my hair and tell me what I am doing wrong.
Thanks!
Joe
|
|

11-17-2005, 12:36 PM
|
 |
Ultimate Contributor
Retired Leader * Guru *
|
|
Join Date: Aug 2001
Posts: 5,343
|
|
|
Once you set totalTime just set the label's caption = to totalTime. No further calculation is necessary.
|
|

11-17-2005, 12:52 PM
|
|
Regular
|
|
Join Date: Oct 2005
Posts: 65
|
|
|
Still not working
Here is what I have...
'Display Totals in labels
mins = DateDiff("m", dteInfonetStart, dteInfonet)
totalTime = Format$(CLng(mins / 60) & ":" & mins Mod 60, "hh:mm")
lblInfonetTotal.Caption = totalTime
|
|

11-17-2005, 01:43 PM
|
 |
Unashamed geek
Retired Moderator * Expert *
|
|
Join Date: Jul 2003
Location: London, England
Posts: 8,988
|
|
Simple subtraction is a perfectly valid method of calculating time differences.
This works just fine for me:
Code:
dteInfonetStart = TimeSerial(22, 30, 0)
dteInfonet = TimeSerial(22, 35, 0)
Debug.Print Format$(dteInfonet - dteInfonetStart, "hh:nn")
'prints 00:05
DateDiff is useful if you want the difference measured in a particular unit. For example if you want the difference in weeks between two dates.
In this case, DateDiff just complicates things because then you need to do all the division and Mod etc.
If, however, you prefer DateDiff for some reason, then use "n" as interval and not "m" ("m" is for months).
|
|

11-18-2005, 07:26 AM
|
|
Regular
|
|
Join Date: Oct 2005
Posts: 65
|
|
|
This code does work however you have put the values in the code and while the start time never changes the dteInfonet in input data that will change everyday it is entered. so I need it to read the input value and minus it from the start value.
Ending time minus Start Time = Total time it took to backup servers. This is very close but not quite right yet. Any other ideas?
|
|

11-18-2005, 12:49 PM
|
 |
Unashamed geek
Retired Moderator * Expert *
|
|
Join Date: Jul 2003
Location: London, England
Posts: 8,988
|
|

The first two lines of code were there just to provide some sample data...
The 3rd line of code is all you need.
|
|

11-18-2005, 02:29 PM
|
|
Regular
|
|
Join Date: Oct 2005
Posts: 65
|
|
|
I am still getting the 00:00 in the results. Can anyone tell me what I am doing wrong.
|
|

11-18-2005, 02:44 PM
|
 |
Ultimate Contributor
* Expert *
|
|
Join Date: Apr 2004
Location: Illinois
Posts: 2,499
|
|
|
What is your line of code now? Probably somethin' really simple gone wrong.
|
__________________
Insomnia is a simple byproduct of "it can't be done" {Window Shaper}
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|