VB Script to record and write current system time.
Hi All,
I need a vbscript which with record the current system date and time in the format [YYYY-MM-DD HH:MM:SS] and append the same in between a string in a ini file ;
Say:
ACCEPT, 90.136.18.140,Security Manager,2009-04-20 00:42:11 , PERPETUAL, 4000, BIgui"
Thank you in advance.
I need a vbscript which with record the current system date and time in the format [YYYY-MM-DD HH:MM:SS] and append the same in between a string in a ini file ;
Say:
ACCEPT, 90.136.18.140,Security Manager,
Thank you in advance.
0 Comments
[ + ] Show comments
Answers (13)
Please log in to answer
Posted by:
anonymous_9363
15 years ago
Is there some reason why you have re-jigged your question http://itninja.com/question/gnu,-freeware-and-shareware-programs-to-cloning9460 and posted it in a different forum? The answer is the same (well, from me, anyway). Use the class - it will save you a lot of work.
As for the date part, you can do all sorts of re-jigging with string manipulation. Here's a ChangeDateFormat function, to which you could add different formats (to save re-writing the same code over and over). It takes the date (normally from the Now() statement) and uses the various date/time handling statements like Day, Month, Year and so on to split the return value from Now() into its constituent parts. It then re-constitutes them according to a format integer passed in to the function.
As for the date part, you can do all sorts of re-jigging with string manipulation. Here's a ChangeDateFormat function, to which you could add different formats (to save re-writing the same code over and over). It takes the date (normally from the Now() statement) and uses the various date/time handling statements like Day, Month, Year and so on to split the return value from Now() into its constituent parts. It then re-constitutes them according to a format integer passed in to the function.
'//=========================================================================================================
'// Name: ChangeDateFormat
'// Purpose: Converts date to different formats
'// Also adds leading zeroes to days, hours, minutes & seconds
'// Input: strDate - a string containing the date in its current format
'// intFormatToUse - an integer indicating which format to convert TO
'// Output: strNewDate - a string to contain the converted date
'// Returns: True/False
'//
'//=========================================================================================================
Function ChangeDateFormat(ByVal strDate, ByVal intFormatToUse, ByRef strNewDate)
Dim strYear
Dim strMonth
Dim strDay
Dim strHour
Dim strMinute
Dim strSecond
ChangeDateFormat = False
If Len(strDate) = 0 Or IsNull(strDate) = True Then
strNewDate = ""
Exit Function
End If
ChangeDateFormat = True
strDay = Day(strDate)
strMonth = Month(strDate)
strYear = Year(strDate)
strHour = Hour(strDate)
strMinute = Minute(strDate)
strSecond = Second(strDate)
If strMonth < 10 Then
strMonth = "0" & strMonth
End If
If strDay < 10 Then
strDay = "0" & strDay
End If
If strHour < 10 Then
strHour = "0" & strHour
End If
If strMinute < 10 Then
strMinute = "0" & strMinute
End If
If strSecond < 10 Then
strSecond = "0" & strSecond
End If
Select Case intFormatToUse
Case intDateFormat
strNewDate = strDay & "-" & strMonth & "-" & strYear
Case intTimeFormat
strNewDate = strHour & ":" & strMinute & ":" & strSecond
Case intDateTimeFormat
strNewDate = strDay & "-" & strMonth & "-" & strYear & " " & strHour & ":" & strMinute & ":" & strSecond
Case intDateSpaceFormat
blnResult = GetMonthName(intMonth, True, strMonth)
strNewDate = strDay & " " & strMonth & " " & strYear
Case intDateTimeSpaceFormat
blnResult = GetMonthName(intMonth, True, strMonth)
strNewDate = strDay & " " & strMonth & " " & strYear & " " & strHour & ":" & strMinute & ":" & strSecond
Case intGPOFormat
strNewDate = strYear & strMonth & strDay & strHour & strMinute & strSecond
Case intWMIFormat
strNewDate = strYear & strMonth & strDay & strHour & strMinute & "00.000000+***"
Case Else
strNewDate = strDay & "-" & strMonth & "-" & strYear & " " & strHour & ":" & strMinute & ":" & strSecond
End Select
End Function
Posted by:
bubble_buzz21
15 years ago
Hi
I have not rejigged my question
Kindly read my question carefully, this is for a totally different issue.
My previous question was pertaining
"which will read a ini file with a keyword and when it finds out the keyword it will delete the line that contains the keyword "
Hope this answers your query.
I have not rejigged my question
Kindly read my question carefully, this is for a totally different issue.
My previous question was pertaining
Hope this answers your query.
Posted by:
anonymous_9363
15 years ago
Oh, come on! LOL
Use the class file. It'll do what you want and some.For the other parts of the string you want to add, get the value with the GetINIValue function from the class, use Split with the comma as the separator, replace element 4 (actually 3, as arrays are zero-based) with the re-formatted date, add the remaining elements, then write the new value using WriteINIValue.
How hard is that?
Use the class file. It'll do what you want and some.For the other parts of the string you want to add, get the value with the GetINIValue function from the class, use Split with the comma as the separator, replace element 4 (actually 3, as arrays are zero-based) with the re-formatted date, add the remaining elements, then write the new value using WriteINIValue.
How hard is that?
Posted by:
bubble_buzz21
15 years ago
Hi
Rather than using all the cumbersome scripts here is a script which will serve the purpose :
sDate = Date
Dim FTime
Dim MTime
MTime = FormatDateTime(Time, 4)
FTime = Right("0" & Hour(MTime), 2) & ":" & Right("0" & Minute(MTime), 2) & ":" & Right("0" & Second(Time), 2)
Wscript.Echo "Date is: " & Year(sDate) & "-" & Right("0" & Month(sDate),2) & "-" & Right("0" & Day(sDate), 2) & " " & FTime
Rather than using all the cumbersome scripts here is a script which will serve the purpose :
Dim FTime
Dim MTime
MTime = FormatDateTime(Time, 4)
FTime = Right("0" & Hour(MTime), 2) & ":" & Right("0" & Minute(MTime), 2) & ":" & Right("0" & Second(Time), 2)
Wscript.Echo "Date is: " & Year(sDate) & "-" & Right("0" & Month(sDate),2) & "-" & Right("0" & Day(sDate), 2) & " " & FTime
Posted by:
anonymous_9363
15 years ago
Posted by:
bubble_buzz21
15 years ago
Posted by:
anonymous_9363
15 years ago
Posted by:
bubble_buzz21
15 years ago
I guess there are people who have no better work in the world and who think they have taken the monoply over this site and can sit and comment on others blog in any way they feel like.
No one learns scripting in one day dude. People make mistakes but you should know how to reply guess you shold first learn that.
SO YOU BETTER NOT COMMENT ON MY QUERIES FROM NEXT TIME.
No one learns scripting in one day dude. People make mistakes but you should know how to reply guess you shold first learn that.
SO YOU BETTER NOT COMMENT ON MY QUERIES FROM NEXT TIME.
Posted by:
anonymous_9363
15 years ago
Posted by:
bubble_buzz21
15 years ago
Posted by:
anonymous_9363
15 years ago
seems people like you have more time to pick up fight then resolving issuesEr, remind who it was that started making "threats"?
you couldnt resolve my issue"Dude", I could have resolved it in my sleep: I write software which people pay for. You, however, seem to belong to the modern school of software development - ask other people to do the work for free and then slag them off when the going gets even marginally beyond page five of "Scripting For Dummies." Cheerio.
Posted by:
bubble_buzz21
15 years ago
Ur code shows dat u really write in ur sleep and people pay for a that.... then why dont u excuse urself from my queries n go to "people" who can afford to pay you for ur script.
BTW if you follow the mail thread you can c who started all the so called great comments...i just posted the script which worked for me so , n whats so wrong if your script dint work out for me..i guess it was not meant an offence for u if my small script served the purpose rather then using a bulky script...dude guess u take things to personally when ur resolution dont work out.
I think this is a free site for resolution and you are too much in need of money no wonder u always mention that.
Think global recession is taking a toll over evryone.
BTW if you follow the mail thread you can c who started all the so called great comments...i just posted the script which worked for me so , n whats so wrong if your script dint work out for me..i guess it was not meant an offence for u if my small script served the purpose rather then using a bulky script...dude guess u take things to personally when ur resolution dont work out.
I think this is a free site for resolution and you are too much in need of money no wonder u always mention that.
Think global recession is taking a toll over evryone.
Posted by:
bkelly
15 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.