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

Newbie question... 2

Status
Not open for further replies.

B14speedfreak

Technical User
Mar 23, 2006
182
Hi all,

Guess I am one of those people that Microsoft hate. Normally I spend most of my time using Unix/Linux and my desktop OS doesn't get used that much since I work with Oracle instances quite lot.

Anyhow my question is this. Is there a way of setting a date as a enviroment variable in XP pro???

thanks again,

B14... aka... Marky Mark... the frozen monkey in the server room...
 
You mean a specific date? or todays date?

Hope this Helps.

Neil J Cotton
njc Information Systems
Systems Consultant
 
obviously i meant the current date!

To set current date, you could create script, or regedit, or batch, that enters the current date straight into the registry data for environment variables, put it in start up, and also as a schedule to run daily at midnight.

Hope this Helps.

Neil J Cotton
njc Information Systems
Systems Consultant
 
I will have a look at this. Thanks for the post. See in Unix we have an enviroment variable set up called $DATE so we just do: echo $date to the todays date!

Sorry for not making it obvious what I meant in the above post.

Thanks again,


B14... aka... Marky Mark... the frozen monkey in the server room...
 
Think I really am a newbie in windows... any chance you could show me how to do this?? or could you point me to any sites that specialize in tutorials for scripting in windows?

thanks again,

B14... aka... Marky Mark... the frozen monkey in the server room...
 
you can get the date at run time, but depends what you want to do with it, or more importantly, what tool needs it, and whether it has the option to run a GetDate function, otherwise have the function run before hand, and write to registry, and then just use normal windows environment variable reference.

i've not run/tested this, but should be something like this

Code:
Dim WSHShell, RegKey, EnvVarReg
oDate=Date()
set WshShell = CreateObject("WScript.Shell")
set oEnv=WshShell.Environment("System")
oEnv("TodaysDate") = oDate

Hope this Helps.

Neil J Cotton
njc Information Systems
Systems Consultant
 
infact remove that declerations from RegKey, and EnvVarReg, they are from an old script i wrote for creating a env var from a registry key

should be
Code:
Dim WSHShell
oDate=Date()
set WshShell = CreateObject("WScript.Shell")
set oEnv=WshShell.Environment("System")
oEnv("TodaysDate") = oDate

Hope this Helps.

Neil J Cotton
njc Information Systems
Systems Consultant
 
You could create a notepad file and type this in...

Code:
msgbox Date

Then save it as YourFilename.vbs (vbs is for VBScript). Then you double click on the file or store it somewhere and open it in whatever fashion you want and you'll get a message box popup with the current system date in it.

HTH

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
Yeah see I wanted it as an enviroment variable so that I could reference it in a file name.

In unix I can do the following for a file name:

mark$date.dbf

this might give:

mark270706.dbf

can I do the same in windows?

Thanks for the posts they are really useful,



B14... aka... Marky Mark... the frozen monkey in the server room...
 
1. Download XSET538.zip, unzip it, and place XSET.EXE into C:\Windows\System32

Your command in a .bat file would then be:

@echo off
xset d date DD
xset m date MM
xset y date YY
echo "mark%d%%m%%y%".dbf

2. Native XP

Start, Run, CMD

(I am using echo here to create an empty file)

Type:
echo >mark%date:~-4%%date:~4,2%%date:~7,2%.dbf

Then use Dir to see the result
 
ah right... I will have a look at some point... probably tommrrow I guess now though... thanks for the posts though guys, they are really useful...



B14... aka... Marky Mark... the frozen monkey in the server room...
 
just put my script in startup, and schedule to run every day at midnight with windows scheduler, then the variable will be set every logon and everyday ay midnight, well, set it to 12:01.

Hope this Helps.

Neil J Cotton
njc Information Systems
Systems Consultant
 
Fwiw, Date will retreive the system date (no time), Time will retreive the system time (no date) and Now will retreive the system date and time (aka Date + Time).

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
Yes, but use either Date() or Now(). My concern is the format output for use in a file name. Obviously 7/27/2006 is not a great idea for a filename.
 
There is also the VBScript function FormatDateTime...

Code:
MsgBox FormatDateTime(Date, 1)

The format constants are:

[tt]Constant Value Description
vbGeneralDate 0 Display a date in format mm/dd/yy. If the date parameter is Now(), it will also return the time, after the date
vbLongDate 1 Display a date using the long date format: weekday, month day, year
vbShortDate 2 Display a date using the short date format: like the default (mm/dd/yy)
vbLongTime 3 Display a time using the time format: hh:mm:ss PM/AM
vbShortTime 4 Display a time using the 24-hour format: hh:mm[/tt]

For more info, check out:


For all VBScript functions:


HTH

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
Zack,

You still have to process the "/" seperators.

I still think this is the easiest:

SET FILEDATE=%date:~-4%%date:~4,2%%date:~7,2%



 
The best place and method to do this is directly. XP provides in the System Property Sheet:

Right-click My Computer, Properties, Advanced, Environment Variables (at bottom).

Use Add in the bottom box to create a new System variable:

FILEDATE=%date:~-4%%date:~4,2%%date:~7,2%

Done! No scheduled tasks needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top