Timestamp once again

Hi,

Recently Thomas answered my question about how to obtain a timestamp with the following:

dim d As new date
system.Log System.LogLevelError, “Timestamp :” + d.ShortDate +" " + d.ShortTime

Probably I phrased by question the wrong way. What I want is a way of inserting the current time (hrs, mins, secs) in a message sent to my own message file. As this:

Dim msg as String
msg = “This is my message” + timestamp

How would I go about to realise this?

Strange

Dim d As New Date() Dim msg as String = "This is my message " + _ Format(d.Hour, "00") + ":" + Format(d.Minute, "00") + ":" + Format(d.Second, "00")

If it is a log file of sorts, I’d use Eli’s method as you will have a consistent time easy to read/parse, i.e. 05:15:22. If for human consumption, you can of course use Eli’s method but with d.ShortTime instead of the individual Format calls.

logger “this is a message”

function logger(msg as string)
dim d as new date

dim ds as string = d.sqldatetime
ds.replaceall(":","")
ds.replaceall("-","")

system.log ds +  " : " + msg

// or write it to a file

end function

i would advise logging using yyyymmddhhmmss because…

  1. it will still work if you go over midnight boundaries
  2. if you log to an external file the fact that the dates are in sequence will allow you to lift it into excel and sort/filter very Easilly.

[quote=105019:@Russ Lunn]i would advise logging using yyyymmddhhmmss because…

  1. it will still work if you go over midnight boundaries
  2. if you log to an external file the fact that the dates are in sequence will allow you to lift it into excel and sort/filter very Easilly.[/quote]

If for a log, indeed include the full date/time. Also, the d.SQLDateAndTime format might actually be better for a log? It is a bit more readable as humans will be looking at the log from time to time I’d guess, Excel should still be able to parse the date fine and the dates are still sequential (text in a file or via Excel’s sort).

For example:

20140627085711 - my message
2014-06-27 08:57:11 - my message

you’re right of course.

some people just cant read the matrix :wink:

or in teh heat of the moment when stuff is broken, it is harder to read. Someone that has to do “Ops” along with dev and engineering, make your “Ops” moments as easy for you as possible.

Personally I just use “d.SQLDateTime” and my timestamp. it might not be perfect but it is easy to read and and understand.

Thanks to all for interesting replies.

I shall be using:

Dim d As New Date
MsgBox(Str(d))

Best regards,

Strange