ZTree.com  | ZEN  | About...  

 Index   Back

[Q] Ctrl-Batch Parameters for separated Date/Time variables?   [Q]

By: Ben Kent       
Date: Jan 18,2024 at 09:52
In Response to: [Q] Ctrl-Batch Parameters for separated Date/Time variables? (Dan LeGate)

> I notice %d and %dm return date formats in:
> " 1-17-2024 6:01:21 pm"
> format.
> Are there any parameters available that would return just the pieces of
> the dates separated into month / day / year / hour / minute / second /
> am-pm?
> Example:
> %x1 = 01
> %x2 = 17
> %x3 = 2024
> %x4 = 06 (or 18, for 24hr)
> %x5 = 01
> %x6 = 21
> %x7 = pm
> Sure would be handy for scripting.


The format is probably controlled by CO-1K and CO-1L

You could do this in your script

@echo off
REM Assuming the date is in the first parameter
REM Strip the quotes from the commandline
Set "DT=%~1"
REM Get the parts, WARNING: will need to be adjusted for different date formats
echo Month _%DT:~1,2%_
echo Day _%DT:~4,2%_
echo Year _%DT:~7,7%_
echo Hour _%DT:~12,2%_
echo Minute _%DT:~15,2%_
echo Second _%DT:~15,2%_
echo Meridiem _%DT:~21,2%_

To not have scripts broken when the date format changes it would be better to extend %d to something like this

where x is m=modified, c=created, a=accessed
and y is
m Month
d Day, D could mean without leading zero
y Year, Y could mean without century
h Hour
n Minute, or M if it's case sensitive, or keep n and use upper case to strip the leading zero
s Second
p Meridiem

From one of my scripts, which is roughly standard
%c Date and time representation appropriate for locale
%d Day of month as decimal number (01 - 31)
%D Day of month as decimal number (1 - 31)
%H Hour in 24-hour format (00 - 23)
%I Hour in 12-hour format (01 - 12)
%j Day of year as decimal number (001 - 366)
%J Julian date
%m Month as decimal number (01 - 12)
%M Minute as decimal number (00 - 59)
%p Current locale's A.M./P.M. indicator for 12-hour clock
%Q Quarter of the year
%S Second as decimal number (00 - 59)
%U Week of year as decimal number, with Sunday as first day of week (00 - 51)
%w Weekday as decimal number (0 - 6; Sunday is 0)
%W Week of year as decimal number, with Monday as first day of week (00 - 51)
%x Date representation for current locale
%X Time representation for current locale
%y Year without century, as decimal number (00 - 99)
%Y Year with century, as decimal number
%z Time-zone name
%Z Time-zone abbreviation
%O Current time zone offset



Messages in this Thread

96,664 Postings in 12,235 Threads, 350 registered users, 199 users online (0 registered, 199 guests)
Index | Admin contact |   Forum Time: Jun 16, 2024 - 2:45 pm UTC  |  Hits:64,849,442  (59,502 Today )
RSS Feed