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

Date formats when interacting with Active Directory

Status
Not open for further replies.

krinid

Programmer
Jun 10, 2003
356
CA
When working with dates with Active Directory, the date is relative to the format specified on the local PC. Does anyone know of a way to force a particular format when using Active Directory independent of the local date format?

The problem I'm having is that the input files this script will run on contains dates that will be in a single format (yyyy/mm/dd) regardless of the computer it runs on and the local date format. (eg: People in North America generally use mm/dd/yyyy, but people in Europe and Asia often use yyyy/mm/dd, and others use dd/mm/yyyy, but these can be freely customized as well, etc).

The actual relevant code is as follows:
Code:
Set objUser = GetObject ("LDAP://...")
objUser.AccountExpirationDate = "2008/11/11"
 
Why not create your own custom function to format the date/time however you need/want it to be?

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
That's what I'd like to do, but I'm not sure how.

I'm trying to avoid doing this:
a) verify the format of the PC
b) compare it to the input file
c) adjust if necessary

I don't want to have to query the local PC for the date format. I'd like to be able to pass the date value into AD and provide it the date format.

eg: if my input data is 2008/11/12, instead of querying the local PC to find that the format is mm/dd/yyyy and converting 2008/11/12 to 11/12/2008 and passing that in, I'd rather still pass 2008/11/12 into AD and tell it that the format I'm using is yyyy/mm/dd.

Especially since local formats can vary widely and can even be odd, custom inventions, I don't want to deal with local formatting at all.
 
VBScript provides you with
Month()
Day()
Year()
functions which you can then use to put together in the format you want.

Code:
Option Explicit

Dim currentDate : currentDate = Date()

WScript.Echo currentDate

Dim intMonth : intMonth = Month(currentDate)
Dim intDay : intDay = Day(currentDate)
Dim intYear : intYear = Year(currentDate)

WScript.Echo intYear & "/" & intMonth & "/" & intDay
' need padding
WScript.Echo intYear & "/" & Right("00" & intMonth, 2) & "/" & Right("00" & intDay, 2)

create a function and you're all set.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top