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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add the current time in a column 2

Status
Not open for further replies.

arlinda

Technical User
Feb 20, 2008
32
US
Hi,

I would like to know how to add the current time in my Modification column. This column is emty. This file is a text file and I dod not know how to create a script using ADO. Please advice. This is what I have so far.

'On Error Resume Next

Const ForReading = 1
Const ForWriting = 2


'open the data file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\data\abc.csv", ForReading)


strContents = objFile.ReadAll
objFile.Close

strFirstLine = "First Name, Middel int, Last name, Start Date, ModificationDate"

strNewContents = strFirstLine & vbCrLf & strContents
Set objFile = objFSO.OpenTextFile("C:\data\abc.csv", ForWriting)
objFile.WriteLine strNewContents

objFile.Close

 
Code:
strNewContents = strFirstLine & vbCrLf & strContents & ", Modified:" & Now

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Hi,

Is it possible to add the current date in the ModificationDate Column?

Thank you.
 
Anything is possible but you have given no details on what you are importing to know the full data structure.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Hi,

My file includes Peoples First name, middle Initial, Last Name and Date. I am adding another column called ModificationDate. I would like to populate the modificationDate column with the current date.

For example, this is what I am trying to acomplish
First name, middle Initial, Last Name,Date,ModificationDate
ann, j, abc,1/2/1980, 2/26/2008 9:02:35

Below is my script, Please advice.


'On Error Resume Next

Const ForReading = 1
Const ForWriting = 2


'open the data file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\data\abc.csv", ForReading)


strContents = objFile.ReadAll
objFile.Close

strFirstLine = "First Name, Middel int, Last name, Start Date, ModificationDate"

strNewContents = strFirstLine & vbCrLf & strContents
Set objFile = objFSO.OpenTextFile("C:\data\abc.csv", ForWriting)
objFile.WriteLine strNewContents
strNewContents = ModificationDate

If strNewContents <> "" Then
strNewContents = Now
objFile.WriteLine strNewContents

else
objFile.Close
End
 
...
strContents = objFile.ReadAll
objFile.Close
strFirstLine = "First Name, Middel int, Last name, Start Date, ModificationDate"
Set objFile = objFSO.OpenTextFile("C:\data\abc.csv", ForWriting)
objFile.WriteLine FirstLine
arrContents = Split(strNewContents, vbCrLf)
For i = 0 To UBound(arrContents)
objFile.WriteLine arrContents(i) & "," & Now
Next
objFile.Close

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi,

I made the changes to the script. It adds the current time but it also adds the current time next to the modificationDate header. For example

First Name, Middel int, Last name,ModificationDate,2/26/2008 11:24:03 AM

This is what I did in my script but when I compile it, my script does not add the header. It just adds the current time to the file.


strContents = objFile.ReadAll
objFile.Close
strFirstLine = "First Name, Middel int, Last name, Start Date, ModificationDate"
Set objFile = objFSO.OpenTextFile("C:\data\abc.csv", ForWriting)

arrContents = Split(strNewContents, vbCrLf)
For i = 0 To UBound(arrContents)
i = i + 1
objFile.WriteLine arrContents(i) & "," & Now
Next
objFile.Close
 
So add the date first then add the header last. By the way, watch out for commas in your data.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
You missed this line (please, reread my previous post):
objFile.WriteLine FirstLine
 
Hi,

I did add the objFile.WriteLine FirstLine but when I looked at my modifide file,
it had opied the same information twice. One that had the header and text. The second had header, text and current date
I also did paste exactly what you had posted

objFile.WriteLine FirstLine
arrContents = Split(strNewContents, vbCrLf)
For i = 0 To UBound(arrContents)
objFile.WriteLine arrContents(i) & "," & Now
Next
objFile.Close


When I compiled the script my text file was blank


I tried reversing the code. But when I compiled it printed the header only not the current date.
Any Advice
 
Post exactly what you are currently running.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Thank you guy's I just figured it out.

objFile.WriteLine strFirstLine
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top