SS>Is there some way to automatically determine whether the date is
SS>held in MM/DD/YY format as in the US or DD/MM/YY as in the UK

SS>Think one of you BTM gurus could come up with this universal
SS>Julian fix?.

I whipped up a little batch file called UNIDATE.BTM.  Can't say if it
works for date formats other than mine (U.S.), but it looks good. <g>
It isn't short enough to make into an alias, but I'm relatively sure
somebody will remedy that.  ;-)

It works by plugging Jan 13, 1980 into the %@date[] function using the
various date formats.  If the result is 12, it calls *date with the
proper format.  There's no error checking, so the worst you'll get is a
large, strange number if the guess is wrong.

Since the YYMMDD format is the most logical, I decided to use that as a
standard.  'Course, you can change it (as always).  Just setup an alias
like this: DATE=call unidate.btm, and you can add whatever else you've
currently got.  For example, my date alias is:

DATE=iff "%1"="" then^echo %_dow, %_date^else^*date %1^endiff

So I'd change it to:

DATE=iff "%1"="" then^echo %_dow, %_date^else^call unidate.btm %1^endiff

That said, here's v0.90 (beta) of UNIDATE.BTM:

set _y=%@substr[%1,0,2]
set _m=%@substr[%1,3,2]
set _d=%@substr[%1,6,2]

iff %@date[1-13-80] EQ 12 then
  *date %_m%/%_d%/%_y%
elseiff %@date[13-1-80] EQ 12 then
  *date %_d%/%_m%/%_y%
elseiff %@date[80-1-13] EQ 12 then
  *date %_y%/%_m%/%_d%
elseiff %@date[80-13-1] EQ 12 then
  *date %_y%/%_d%/%_m%
else
  echo Unknown date format!
endiff

unset _y _m _d


SS>Is there some way to automatically determine whether the date is
SS>held in MM/DD/YY format as in the US or DD/MM/YY as in the UK and
SS>many other countries and make the appropriate mods to mont, date
SS>and day of week calculations.

Steve:  Try this.  Someone suggested this when I asked this question
some time ago.  It's silly, but it works.

set td=%@substr[%@makedate[1],0,2]          <- 2 January 1980
iff "%td"=="01" then                        <- 01-02-80
  set ypos=6^set mpos=0^set dpos=3
elseiff "%td"=="02" then                    <- 02-01-80
  set ypos=6^set mpos=3^set dpos=0
elseiff "%td"=="80" then                    <- 80-01-02
  set ypos=0^set mpos=3^set dpos=6
endiff
set dt=%_date
set year=%@substr[%dt,%ypos,2]
set month=%@substr[%dt,%mpos,2]
set day=%@substr[%dt,%dpos,2]


SL>Yeah, different YEARS will cause problems!  YY-MM-DD format is the only
SL>way to always get a proper comparison, but this is hardly news to us
SL>who have been programming for years!

So why do you keep insisting that a direct string comparison will work?
I don't think anybody wants a BTM that will fail annually.

SL>I started programming in 1971 and learned that to do it correctly is
SL>VERY messy because of such problems! I was trying not to be overly
SL>complicated here!  Sigh!

The %@date[] wrapper is a little more complicated, but I believe it's
well worth the effort.  It transcends the various date formats as well
as the upcoming century boundary.

Actually, %@date[] is the only viable test for those using the European
codepage (dd-mm-yy).  There's plenty of people in this echo from "across
the pond".

But all this aside, how about a copy of UNIDATE.BTM?  It will accept
YY-MM-DD format regardless of the current codepage.  Of course, I chose
that format because it's most convenient for manipulation.  You can
change the accepted format to suit your preferences by rearranging the
y, m, and d in the first line.

REM * Start of UNIDATE.BTM
REM UniDate.Btm by Dave M. Walker, 1:396/1
set y=%@substr[%1,0,2]^set m=%@substr[%1,3,2]^set d=%@substr[%1,6,2]
iff %@date[1-13-80]==12 then^*date %m-%d-%y
elseiff %@date[80-1-13]==12 then^*date %y-%m-%d
elseiff %@date[13-1-80]==12 then^*date %d-%m-%y
endiff^unset y m d
REM * End of file

This works because %@date[] does no error checking (for a YY-MM-DD
format, the first IFF will attempt to get the number of days since
2001-13-80).  Jan 13, 1980 is the first non-ambiguous date, so it's used
for the tests.

