Best way to validate a string is a YYYYMMDD

Charles Dye

Super Moderator
Staff member
May 20, 2008
Albuquerque, NM
@ISDATE will tell you whether it's a valid date, but not whether it's in the format you want. For example, %@ISDATE[05-23-68] will return 1, even though the date isn't YYYYMMDD. Assuming that you already know the length is 8 characters, you could check for both a valid date and the desired format in one swell foop with something like:

if "%@isdate[%cdate]%@isdigit[%cdate]" == "11" echo Valid date in YYYYMMDD format.

(But note that my idea of a "valid date" includes dates well out of TCC's supported date range.)

Charles Dye

Super Moderator
Staff member
May 20, 2008
Albuquerque, NM
From the included HTML: %@ISDATE[date,infmt] so couldn't I use %@isdate[%cDate,YYYYMMDD] ??

That second parameter is only used to interpret ambiguous date formats, like 05-11-12. It doesn't enforce any format.

(Klaus's solution is also quite clever; have you checked it out? TCC will happily accept some invalid dates, the 30th of February or whatever. But pushing such an invalid date through @DATE and then @MAKEDATE will give you a valid date back -- which will necessarily be a different string from the one you started with. Elegant!)
Similar threads
Thread starter Title Forum Replies Date
S How to? best way to compose data for command to use out of presets/variables Support 1
p.f.moore Best way of embedding data in a BTM file Support 12
A Best Practice for TCMD11 Windows7 64 Support 2
R best file compare util Support 5
tinjaw Looking for best practice for custom environment on tabs Support 0
p.f.moore Best way to keep a copy of a directory Support 3
P Inserting string into a variable. Support 3
M Backquoted parameters used in GoSub don't pass string as a single parameter Support 2
H Behavior change re piping a string to a Java program Support 1
C email[string] function Support 10
D Finding a string position in a larger string Support 2
MikeBaas How to...extract a string from a .json-file? Support 10
D Faster string search Support 8
D btm file command line augments comparing for string or math. Support 12
B How can TCC make an output as a part of command string Support 2
vefatica DO /L, where did my string go? Support 6
Alpengreis A leading withespace in Hash-String is not included? Support 1
T TPipe: Replacing String with Double Quotes Support 3
J WAD utf8decode string only results in ? chars Support 2
scooter_de How to? How to split the a string? Support 4
C custom string compare? Support 8
Phileosophos Documentation TPIPE /string type code confusion Support 4
vefatica WAD "tokens=*" and literal string Support 4
vefatica Back-refs in TPIPE's /replace's replacement string? Support 2
vefatica @B64ENCODE[s,string]? Support 8
vefatica Random access to the characters in a string? Support 4
vefatica @WORD[], quoted string? Support 8
H "Here-String" redirection not working Support 6
C Can't remove leading quote from a string Support 2

Similar threads