How get data/time independent from localization

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How get data/time independent from localization

#61 Post by aGerman » 11 Jul 2015 06:39

If you execute this command then you get an error I guess?

Correct. The error message is "No valid counters."

Code: Select all

C:\>typeperf "\ICMP\Received Timestamp/sec" -sc 1


Fehler: Keine gültigen Leistungsindikatoren

C:\>

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: How get data/time independent from localization

#62 Post by Ed Dyreen » 11 Jul 2015 07:32

but dateTime object does exist in java and probably javascript too and both do not require .NET framework.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How get data/time independent from localization

#63 Post by aGerman » 11 Jul 2015 07:53

I wonder why MS didn't put an ISO date/time string in CMD.

Easy enough since you will seldom find an obsolete Windows version that is not able to access WMI. Thus, your very first answer in this thread should always work nowadays.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How get data/time independent from localization

#64 Post by foxidrive » 11 Jul 2015 09:39

aGerman wrote:
I wonder why MS didn't put an ISO date/time string in CMD.

Easy enough since you will seldom find an obsolete Windows version that is not able to access WMI. Thus, your very first answer in this thread should always work nowadays.


I'm wondering - does WMIC require admin access?

MS really should have put an ISO date-time string in DOS 4 when it became obvious that people everywhere were asking how to manipulate date and time, and that padding and juggling the terms in different regions was a common issue.

I can't believe that nobody in their camp noticed it. :D

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How get data/time independent from localization

#65 Post by foxidrive » 11 Jul 2015 09:52

Ed Dyreen wrote:dateTime object does exist in java and probably javascript too and both do not require .NET framework.


Can they be leveraged into a batch script in some way, which a regular user account can run?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How get data/time independent from localization

#66 Post by aGerman » 11 Jul 2015 10:00

I'm wondering - does WMIC require admin access?

At work (where I don't have admin authorization) I'm able to access WMIC. Even though I'm certain that it can be disabled via Group Policy (as well as one can disable the execution of any Batch files or other scripts).

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How get data/time independent from localization

#67 Post by aGerman » 11 Jul 2015 10:09

Can they be leveraged into a batch script in some way, which a regular user account can run?

Why not? Remember Daves getTimestamp.bat
viewtopic.php?p=38387#p38387

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How get data/time independent from localization

#68 Post by foxidrive » 11 Jul 2015 10:26

aGerman wrote:At work (where I don't have admin authorization) I'm able to access WMIC


Ok. I thought I read here and there that it required it. Maybe those were people affected by the group policy.

Can they be leveraged into a batch script in some way, which a regular user account can run?

Why not? Remember Daves getTimestamp.bat
viewtopic.php?p=38387#p38387


Geeze, I'm past it. Thanks, I forgot Dave's batch file, even though it's used in scripts at my place.

Dave's bat uses jscript - which someone said recently is Microsoft's version of javascript.

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: How get data/time independent from localization

#69 Post by Aacini » 11 Jul 2015 12:16

Ok. I talked about this point before, so here it is again!

In this and other similar topics, several methods to get the date/time in a locale independent way are presented. These methods are based on external commands, like wmic, makecab, robocopy, reg, typeperf, etc, that frequently are slow. For your information, these are the sizes of such external files: wmic.exe=505,344 byes; makecab.exe=83,968 bytes; robocopy.exe=126,464 bytes; reg.exe=72,192 bytes; typeperf.exe=47,104 bytes. However, no one of these commands were designed to get the date, so the methods takes the date from a secondary output line that have different formats depending on the locale, so the original locale date problem is just replaced by another, similar one, that frequently requires tricky code to extract the result.

Besides, all these methods just get the current date and time; they can not be used to get the date and time of a file, so the file age can be calculated.

I just wanted to remind you that some time ago I wrote a couple auxiliary commands, called StdTime.exe and StdDate.exe, that were designed to get current date and time independently from locale, and to get the same data from files. These .exe files are just 3072 bytes long...

Antonio

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How get data/time independent from localization

#70 Post by aGerman » 11 Jul 2015 13:47

[OT]
jscript - which someone said recently is Microsoft's version of javascript

To cut a long story short: JScript is the Microsoft implementation of the ECMAScript specification while JavaScript is its Netscape/Mozilla implementation. Browser developers created their own implementations with own names but these are not commonly known (neither is JScript). In the common parlance everything is called JavaScript ...
[/OT]

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How get data/time independent from localization

#71 Post by foxidrive » 11 Jul 2015 15:45

Aacini wrote:I just wanted to remind you that some time ago I wrote a couple auxiliary commands, called StdTime.exe and StdDate.exe, that were designed to get current date and time independently from locale, and to get the same data from files. These .exe files are just 3072 bytes long...

Antonio


I thought putting the figures in one line was an easy way to parse the line in a for command, but
the way you handled it in stdtime and stddate is far better - plus they have the extra features.

They are in this archive too, all ready to go: https://www.dropbox.com/s/0nfwl8dpg7hna ... _tools.zip

This is what I see. Do other locales see the same terms?

Code: Select all

c:\>stddate
YYYY=2015
MM=07
DD=12

c:\>stdtime
Hour=07
Min=21
Sec=31
MSec=869

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How get data/time independent from localization

#72 Post by aGerman » 11 Jul 2015 16:24

Do other locales see the same terms?

"YYYY=" and the like are string literals in Antonio's tools. Thus, the output doesn't depend on locales.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How get data/time independent from localization

#73 Post by foxidrive » 11 Jul 2015 23:27

aGerman wrote:
Do other locales see the same terms?

"YYYY=" and the like are string literals in Antonio's tools. Thus, the output doesn't depend on locales.


Aacini's documentation says that the input uses the locale format - so I wondered if it shows JJ or something in another locale.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How get data/time independent from localization

#74 Post by aGerman » 12 Jul 2015 04:12

Code: Select all

C:\Aacini_tools>stddate
YYYY=2015
MM=07
DD=12

C:\Aacini_tools>stdtime
Hour=12
Min=02
Sec=05
MSec=702

C:\Aacini_tools>

:wink:

Aacini's documentation says that the input uses the locale format

Yes, the input does. In Germany the date format is DD.MM.YYYY

Code: Select all

C:\Aacini_tools>stddate 31.07.2015
YYYY=2015
MM=07
DD=31

C:\Aacini_tools>

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How get data/time independent from localization

#75 Post by foxidrive » 12 Jul 2015 05:35

aGerman wrote:
Aacini's documentation says that the input uses the locale format

Yes, the input does. In Germany the date format is DD.MM.YYYY


Doesn't Germany use JJ for day or month? That's what I wondered about.

Post Reply