You can also just subtract minutes… the DateObject is smarter than most people give it credit
d.minute=d.minute-5
and yes it adjusts the hours, days etc.
You can also just subtract minutes… the DateObject is smarter than most people give it credit
d.minute=d.minute-5
and yes it adjusts the hours, days etc.
thanks Dave
Almost there i think. Just struggling to work out how to use the mid() function. I need to stop parsing the log file in this example where dt.SQLDateTime = less than 2013-08-11 07:47:36
[code] dim d as new date
dim time_now as string = d.SQLDateTime
/////////////// 2013-08-11 07:52:36
dim dt as new date
dt.Totalseconds = dt.Totalseconds - 300 // add wanted number of seconds to date
dim time_then as string = dt.SQLDateTime
/////////////// 2013-08-11 07:47:36
Dim f As FolderItem
Dim textInput As TextInputStream
Dim rowFromFile As String
Dim count As Integer =0
f = GetFolderItem(“c:\ex130725.log”)
// From IIS Log File
// 2013-08-11 07:52:36 W3SVC1 CHI-PROD-LTW-1 172.24.50.30 GET /BJLive/Default.aspx?
// 2013-08-11 07:50:12 W3SVC1 CHI-PROD-LTW-1 172.24.50.30 GET /BJLive/Default.aspx?
// 2013-08-11 07:48:36 W3SVC1 CHI-PROD-LTW-1 172.24.50.30 GET /demo.aspx?
// 2013-08-11 04:52:36 W3SVC1 CHI-PROD-LTW-1 172.24.50.30 GET /BJLive/Default.aspx?
// 2013-08-11 03:11:36 W3SVC1 CHI-PROD-LTW-1 172.24.50.30 GET /test.aspx?
// 2013-08-11 02:52:33 W3SVC1 CHI-PROD-LTW-1 172.24.50.30 GET /BJLive/Default.aspx?
If f <> Nil Then
textInput =TextInputStream.Open(f)
textInput.Encoding=Encodings.UTF8
Do
if instr(0,textInput.ReadLine, “BJLive/Default.aspx?”) > 0 then
count = count + 1
Label1.text = Str(count)
end if
Loop Until textInput.EOF
textInput.Close
End If[/code]
dim dt as new date
dim dt2 as new date
dim s a string
dt.Totalseconds = dt.Totalseconds - 300 // add wanted number of seconds to date
/////////////// 2013-08-11 07:47:36
Dim f As FolderItem
Dim textInput As TextInputStream
Dim rowFromFile As String
Dim count As Integer =0
f = GetFolderItem("c:\\ex130725.log")
If f <> Nil Then
textInput =TextInputStream.Open(f)
textInput.Encoding=Encodings.UTF8
Do
s=textInput.ReadLine
dt2=sqldatetime(left(trim(s),19)
if dt2.totalseconds < dt.totalseconds then exit do
if instr(s, "BJLive/Default.aspx?") > 0 then
count = count + 1
end if
Loop Until textInput.EOF
textInput.Close
End If
Label1.text = Str(count)
no need to update label everytime count increments… just when you have a final answer
Dave you are a life saver. Thanks so much.
Pick a charity, I will donate some money online for people less fortunate than us. will CC you in on the thankyou email.
dt2=sqldatetime(left(trim(s),19)
throws me a syntax error have looked at the LR but it’s not that helpfull
What syntax error?
I can see it’s missing a )
I do that a lot lately
dt2=sqldatetime(left(trim(s),19))
If you’re using a windows IDE it may not be you.
Does it still throw the syntax error?
Hi All
Using either of the two lines of code below.
dt2=sqldatetime(left(trim(s),19) - ‘syntax error’
dt2=sqldatetime(left(trim(s),19)) - This method or property does not exist.
[quote] dim dt as new date
dim dt2 as new date
dim s as string
dt.Totalseconds = dt.Totalseconds - 300 // add wanted number of seconds to date
Dim f As FolderItem
Dim textInput As TextInputStream
Dim rowFromFile As String
Dim count As Integer =0
f = GetFolderItem(“c:\ex130725.log”)
If f <> Nil Then
textInput =TextInputStream.Open(f)
textInput.Encoding=Encodings.UTF8
Do
s=textInput.ReadLine
// dt2=sqldatetime(left(trim(s),19)
// dt2=sqldatetime(left(trim(s),19))
if dt2.totalseconds < dt.totalseconds then exit do
if instr(s, “BJLive/Default.aspx?”) > 0 then
count = count + 1
end if
Loop Until textInput.EOF
textInput.Close
End If
Label1.text = Str(count)[/quote]
Thanks Lee
Have you defined the function sqldatetime?
Sorry still a novice and learning albeit slowly. Do you mean a property?
I think the code is wrong. Dave wrote:
dt2=sqldatetime(left(trim(s),19)
and I think it should be:
dt2.sqldatetime = (left(trim(s),19)
Also, I think that Dave’s code:
[code]if dt2.totalseconds < dt.totalseconds then exit do
if instr(s, “BJLive/Default.aspx?”) > 0 then
count = count + 1
end if[/code]
should be written:
if dt2.totalseconds >= dt.totalseconds then
if instr(s, "BJLive/Default.aspx?") > 0 then
count = count + 1
end if
end if
and I think it should be:
dt2.sqldatetime = (left(trim(s),19)
Looks as though the closing bracket is needed
and I think it should be:
dt2.sqldatetime = (left(trim(s),19))
Compiles but
dt2.sqldatetime = (left(trim(s),19))
throws “UnsupportedFormatException”
Is this a bug? have tried console app too and dropped back to 2012 version still getting “UnsupportedFormatException”
Try:
dt2.SQLDateTime = trim(s).Left(19)
dt2.SQLDateTime = trim(s).Left(19)
“UnsupportedFormatException”
Check what “s” is at that moment. An UnsupportedFormatException means that somehow, you’ve fed the SQLDateTime property a string that does not match the format of an SQLDateTime. (I’m wondering also if there’s an encoding issue involving UTF16–I’ve been bitten by that one before.)
Test code:
dim tempString as String
tempString = trim(s).Left(19)
dt2.SQLDateTime = tempString
And watch what the value of tempString is.
had to rewind a little. All getting a little confusing for my tired brain…
[code]
dim s as string
dim d as new date
dim date_time_now as string = d.SQLDateTime
MsgBox(date_time_now)
/////////////// 2013-08-11 07:52:36
dim dt as new date
dt.Totalseconds = dt.Totalseconds - 300 // add wanted number of seconds to date
dim date_time_then as string = dt.SQLDateTime
MsgBox(date_time_then)
/////////////// 2013-08-11 07:47:36
Dim f As FolderItem
Dim textInput As TextInputStream
Dim rowFromFile As String
Dim count As Integer =0
f = GetFolderItem(“c:\ex130725.log”)
// From IIS Log File
// 2013-08-11 07:52:36 W3SVC1 CHI-PROD-LTW-1 172.24.50.30 GET /BJLive/Default.aspx?
// 2013-08-11 07:50:12 W3SVC1 CHI-PROD-LTW-1 172.24.50.30 GET /BJLive/Default.aspx?
// 2013-08-11 07:48:36 W3SVC1 CHI-PROD-LTW-1 172.24.50.30 GET /demo.aspx?
// 2013-08-11 04:52:36 W3SVC1 CHI-PROD-LTW-1 172.24.50.30 GET /BJLive/Default.aspx?
// 2013-08-11 03:11:36 W3SVC1 CHI-PROD-LTW-1 172.24.50.30 GET /test.aspx?
// 2013-08-11 02:52:33 W3SVC1 CHI-PROD-LTW-1 172.24.50.30 GET /BJLive/Default.aspx?
If f <> Nil Then
textInput =TextInputStream.Open(f)
textInput.Encoding=Encodings.UTF8
Do
dim tempString as String
s=textInput.ReadLine
tempString = trim(s).Left(19)
MsgBox(tempString)
//Returns correct trim from readline
//2013-08-11 07:52:36
///###### TRYING TO DO THIS
///###### If "BJLive/Default.aspx?" exist in "s" and "s" date_time_then is NO greater than date_time_now. Then Add to the count.
if instr(s, "BJLive/Default.aspx?") > 0 then
count = count + 1
Label1.text = Str(count)
end if
Loop Until textInput.EOF
textInput.Close
End If[/code]
I am sure it’s just some clever little one liner or two to accomplish this…
Thanks again for any help
Lee
What’s your question?
If anybody can help with a code snippet to do this below. I just can’t work out a way.
///###### If “BJLive/Default.aspx?” exist in “s” and “s” date_time_then is NO greater than date_time_now. Then Add to the count.
Where’s Norman when you need him