Weeble (clockworksaint) wrote,
Weeble
clockworksaint

What's the time, Mr Windows?

In Windows, sometimes you still need to use batch files. If you want to move a bunch of files around, call some programs from the command-line, and still have the same thing work on someone else's computer, they're probably the easiest solution. And batch files today are a lot more flexible than they used to be. But sometimes they can be infuriating.

You can access the current date in the virtual environment variable %date%. For example:
C:\>echo %date%
2008-03-04

C:\>_


Sounds handy, right? Except for the fact that I run it on your machine and it says:
C:\>echo %date%
04/03/2008

or even
C:\>echo %date%
03/04/2008


And in fact, there's no easy way from the command-line to find out what format the date is in, or to request a specific one. The setting is (in Windows XP) in the control panel, under "Regional and Language Options". And it's not even just a fixed list of options - a user can type in their own custom format. There's a sort of sense to this, until you realise that there's not a lot of use for %date% at the command-prompt. You can't dismantle it to find the day, month and year. You can't even use it in a file name, because it might contain backslashes! (Okay, that's not likely, but you can put them in to a customised date format in the control panel.) And if you print it into a log-file (as I do) then the log file might end up with a mix of different formats if the setting is ever changed.

It was while figuring this out that I discovered a further complication. If you have customised your date format, then later go into "Regional and Language Options", fiddle about with the controls, and then cancel, it will discard your customisation, and revert to the default for your region (which is DD/MM/YYYY for UK English). You wouldn't have thought that it would be hard to make a dialog box that just does nothing when you click cancel, but I guess you'd be wrong.
Tags: computers, programming
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 1 comment