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!

objFile.DateCreated 1

Status
Not open for further replies.

roywills

Technical User
Feb 18, 2008
6
US
OK, i am using the

createDateFull = objFile.DateCreated

to get the date/time files are created in one directory. However, it seems that if the date is say 08/23/2007 it grabs it as 8/23/2007. My question is: How can i make it use the leading zero in the variable?
 
I may have fixed this myself, though most likely not as elegant as some could have. here is what i have now to get just the creation date of a file with dashes instead of slashes!:

modDateFull = objFile.DateCreated
modDateNum = Replace(modDateFull,"/","-")
modDate = Left(modDateNum,9)
modDateTrim = RTrim(modDate)
fName = objFSO.GetFileName(objFile)

The RTrim removes the space left after the left command is run if the month is only one digit, and if it has 2 then rtrim does nothing as there is no space.
 
According to the manual, there are no modifiers on this property that would allow you to direct it to return the date padded with zeros. The function would be easy to write, however. I'd suggest breaking it into an array on the "/" character using split and then conditionally padding each index in the array. Use join to then put the string back together. If you put the whole padding operation in a sub, you'll be able to easily use it in other scripts as well later on.
 
Thanks so much Jet042! It pointed out the errors in my ways. My last post will not work as I did not take into account if the day is only 2 characters. I have modified to be this:
-----------------------------------------------------------
For Each objFile in colFiles
modDateFull = objFile.DateCreated
dateArray = Split(modDateFull, "/", -1, 1)
fName = objFSO.GetFileName(objFile)
createdYear = Left(dateArray(2),4)
createdDate = dateArray(0) & "-" & dateArray(1) & "-" & createdYear
-----------------------------------------------------------

the split worked perfectly but since the delimiter between the year and time is just a space i continue to use left to strip the time off the dateArray(2). Since the year will ALWAYS be 4 characters this worked like a charm.

Thanks again to Jet042!
 
I'm glad that worked for you. Thanks for coming back and showing us exactly what you did.
 
Separator is local setting dependent, and the format as well, you could and should avoid that dependency. Instead there are date-time functions to get the answer more generically.
[tt]
modDateFull = objFile.DateCreated
fName = objFSO.GetFileName(objFile)
createdDate = month(modDateFull) & "-" & day(modDateFull) & "-" & year(modDateFull)
[/tt]
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top