Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get system time and how to use append for writing a file

Status
Not open for further replies.

SwingXH

Technical User
Jun 15, 2004
97
US
When I use Time(), it gave me 1899-12-30-06:42:14. The hour is correct. How to get the correct system time including dates?

Also, I want to write an output file with append property, how to write the right code?
Thanks a lot!

SwingXH
 
1) format(time(), "dd/mm/yyyy hh:nn")

2) an example of output

Public Sub ListTables()

Dim tdf As TableDef
Dim strTable As String
Dim i As Integer

i = 0

For Each tdf In CurrentDb.TableDefs

i = i + 1
strTable = tdf.Name
Open CurrentDBDir & "C:\tables.txt" For Append As #i
Write #i, strTable
Close #i

Next tdf

End Sub

------------------------
Hit any User to continue
 
First of all, thank you very much!

I used the following codes,

MyTime = Format(Time(), "dd/mm/yyyy hh:nn")

Open "TESTFILE" For Append As #1

Write #1 MyTime

Close #1

And I got
"30/12/1899 08:14"

The date is not correct(should be 08/09/2004). And how can I remove the quotation mark? ( I want 30/12/1899 08:14 only)

SwingXH
 
Not successfully managed to remove the "" marks myself..

Try Format(Now(), "dd/mm/yyyy hh:nn")

(replace Time with Now)

------------------------
Hit any User to continue
 
Something like this ?
Print #1 Format(Now(), "dd/mm/yyyy hh:nn")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thank you PHV,
assume I have two dates,
MyDate1 = Format(Time(), "dd/mm/yyyy hh:nn")
MyDate2 = Format(Now(), "dd/mm/yyyy hh:nn")

how can I get the difference between them, in terms of days, hours, and minutes?

Thanks,

SwingXH
 
Have you tried something like this ?
Int(MyDate2 - MyDate1) & Format(MyDate2 - MyDate1, " hh:nn")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Type mismatch for

Dim MyDate1, MyDate2 As Date
MyError = Int(MyDate1- MyDate2) & Format(MyDate1 - MyDate2, " hh:nn")

I found this one helpful
MyErrorhh = DateDiff("h", MyDate1, MyDate2)
DateDiff returns a Variant (Long) specifying the number of time intervals between two specified dates.

SwingXH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top