473,385 Members | 1,331 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Date Time problem

I am makeing a program that will track productivity by every time a
button is pushed i write a record to a text file. The text file
contain the time in HHMMSS format. The next time they press a button i
want to read the last time and find the span of time between the two
buttons being pushed. Since I am writing the first time to a text file
i have to pull it back as a string. This would not be a problem until
we get to around midnight and i get a negative number. How can i
convert a string to HHMMSS?
Oct 14 '08 #1
5 2501
"id10t error" <tu******@gmail.comwrote in message
news:60**********************************@w39g2000 prb.googlegroups.com...
>I am makeing a program that will track productivity by every time a
button is pushed i write a record to a text file. The text file
contain the time in HHMMSS format. The next time they press a button i
want to read the last time and find the span of time between the two
buttons being pushed. Since I am writing the first time to a text file
i have to pull it back as a string. This would not be a problem until
we get to around midnight and i get a negative number. How can i
convert a string to HHMMSS?
I thing, for a start, you need as method to prepend the date to your time
string. To the best of my knowledge, both DateTime.TryParse methods require
a date component. Perhaps you could try something like:

Function Build_Date(sTime as string) As Date

Dim tmp as string = Today.ToShortDateString

temp &= " " & sTime.Substring(0, 2) & ":"

temp &= sTime.Substring(2, 2) & ":"

temp &= sTime.Substring(4, 2)

Return CDate(tmp)

End Function

Better still, write the full date and time to your file in the first place.
eg MyDate.ToString("ddMMyyyyhhmmss")

Oct 14 '08 #2
On Oct 14, 4:24*pm, "Harry" <harryNoS...@ffapaysmart.com.auwrote:
"id10t error" <tubbz...@gmail.comwrote in message

news:60**********************************@w39g2000 prb.googlegroups.com...
I am makeing a program that will track productivity by every time a
button is pushed i write a record to a text file. The text file
contain the time in HHMMSS format. The next time they press a button i
want to read the last time and find the span of time between the two
buttons being pushed. Since I am writing the first time to a text file
i have to pull it back as a string. This would not be a problem until
we get to around midnight and i get a negative number. How can i
convert a string to HHMMSS?

I thing, for a start, you need as method to prepend the date to your time
string. To the best of my knowledge, both DateTime.TryParse methods require
a date component. Perhaps you could try something like:

Function Build_Date(sTime as string) As Date

Dim tmp as string = Today.ToShortDateString

temp &= " " & sTime.Substring(0, 2) & ":"

temp &= sTime.Substring(2, 2) & ":"

temp &= sTime.Substring(4, 2)

Return CDate(tmp)

End Function

Better still, write the full date and time to your file in the first place.
eg MyDate.ToString("ddMMyyyyhhmmss")
I do have the full date and time. I could put them together. Would
that help me out?
Oct 14 '08 #3
msgbox(Now)

"id10t error" <tu******@gmail.comwrote in message
news:29**********************************@u29g2000 pro.googlegroups.com...
On Oct 14, 4:24 pm, "Harry" <harryNoS...@ffapaysmart.com.auwrote:
>"id10t error" <tubbz...@gmail.comwrote in message

news:60**********************************@w39g200 0prb.googlegroups.com...
>I am makeing a program that will track productivity by every time a
button is pushed i write a record to a text file. The text file
contain the time in HHMMSS format. The next time they press a button i
want to read the last time and find the span of time between the two
buttons being pushed. Since I am writing the first time to a text file
i have to pull it back as a string. This would not be a problem until
we get to around midnight and i get a negative number. How can i
convert a string to HHMMSS?

I thing, for a start, you need as method to prepend the date to your time
string. To the best of my knowledge, both DateTime.TryParse methods
require
a date component. Perhaps you could try something like:

Function Build_Date(sTime as string) As Date

Dim tmp as string = Today.ToShortDateString

temp &= " " & sTime.Substring(0, 2) & ":"

temp &= sTime.Substring(2, 2) & ":"

temp &= sTime.Substring(4, 2)

Return CDate(tmp)

End Function

Better still, write the full date and time to your file in the first
place.
eg MyDate.ToString("ddMMyyyyhhmmss")

I do have the full date and time. I could put them together. Would
that help me out?
Oct 14 '08 #4
id10t error wrote:
I am makeing a program that will track productivity by every time a
button is pushed i write a record to a text file. The text file
contain the time in HHMMSS format.
Why? That's not a date format that Visual Basic can make sense of, so
why not save yourself a headache or two and use one that it can use?

DateTime.Now.ToString( "yyyy/MM/dd hh:mm:ss" )

will parse back into a DateTime variable very nicely, thank you.
The next time they press a button i want to read the last time and
find the span of time between the two buttons being pushed.
Far better to store this value in the program and calculate the elapsed
time based on that, rather than re-reading the file (which could get
very big and hence very slow to read).

Class Timings
Public Shared gLastActionTime as DateTime = DateTime.MinValue

Public Shared Sub TimedAction(sActionName as String)
Dim dtNow as DateTime = DateTime.Now
Dim lElapsed as Integer = 0

If gLastActionTime <DateTime.MinValue Then
lElapsed = dtNow.Subtract( gLastActionTime ).TotalMilliseconds
End If
gLastActionTime = dtNow

WriteToFile( "{0:yyyyMMdd hh:mm:ss}|{1}|{2}" _
, dtNow, lElapsed, sActionName )

End Sub

HTH,
Phill W.
Oct 15 '08 #5
On Oct 15, 10:41*am, "Phill W." <p-.-a-.-w-a-r...@-o-p-e-n-.-a-c-.-u-
kwrote:
id10t error wrote:
I am makeing a program that will track productivity by every time a
button is pushed i write a record to a text file. The text file
contain the time in HHMMSS format.

Why? *That's not a date format that Visual Basic can make sense of, so
why not save yourself a headache or two and use one that it can use?

DateTime.Now.ToString( "yyyy/MM/dd hh:mm:ss" )

will parse back into a DateTime variable very nicely, thank you.
The next time they press a button i want to read the last time and
find the span of time between the two buttons being pushed.

Far better to store this value in the program and calculate the elapsed
time based on that, rather than re-reading the file (which could get
very big and hence very slow to read).

Class Timings
* * Public Shared gLastActionTime as DateTime = DateTime.MinValue

* * Public Shared Sub TimedAction(sActionName as String)
* * * *Dim dtNow as DateTime = DateTime.Now
* * * *Dim lElapsed as Integer = 0

* * * *If gLastActionTime <DateTime.MinValue Then
* * * * * lElapsed = dtNow.Subtract( gLastActionTime ).TotalMilliseconds
* * * *End If
* * * *gLastActionTime = dtNow

* * * *WriteToFile( "{0:yyyyMMdd hh:mm:ss}|{1}|{2}" _
* * * * * , dtNow, lElapsed, sActionName )

* * End Sub

HTH,
* * Phill *W.
Phill

That seemed to work out great. I like the format better than what i
was using. I thank you for your time and help.
Oct 15 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jay | last post by:
I previously posted this question under Visual Basic newsgroup, but was advised to re-post here. I'm hoping someone can help me solve an issue I'm having with VB.Net and Access 2000. Here's...
7
by: vnl | last post by:
I'm trying to run a SQL query but can't find any records when trying to select a certain date. Here's the sql: SELECT field 1, field2, date_and_time, FROM table1 WHERE date_and_time =...
1
by: Raghu | last post by:
Hello... I am running into a problem while running a query..can some1 help.. this is the query : ************** SELECT * from Table S where S.dtDate1 BETWEEN...
18
by: Robin Lawrie | last post by:
Hi again, another problem! I've moved from an Access database to SQL server and am now having trouble inserting dates and times into seperate fields. I'm using ASP and the code below to get the...
2
by: Riegn Man | last post by:
I have a problem with access and our time clocks. We have time clocks that put out a .log file with the badge swipes for everybody. There is one .log file for each day. I am pulling that data...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
44
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
6
by: Geoff Cox | last post by:
Hello, at the moment I can add the combined date and time into MySQL using php $dt1 = date("Y-m-d H:i:s"); is it possible to add the date and time separately? I thought it might be
10
by: WebCM | last post by:
There is a function: http://paste.ubuntu.com/21865 It needs GMT date in YYYY-MM-DD HH:MM:SS format - in SQL: datetime. If date is the same as today, the function returns "Today". There is one...
16
by: W. eWatson | last post by:
Are there some date and time comparison functions that would compare, say, Is 10/05/05 later than 09/22/02? (or 02/09/22 format, yy/mm/dd) Is 02/11/07 the same as 02/11/07? Is 14:05:18 after...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.