Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Get the name for a month

Getting the name for a month should be a simple function like @months @monthl for the short name and the long name.
But it is not available this sub willl do it for you

:getMonthName
set saveDate=%_date
date /f1 %@makedate[%@date[%monthRequired/1/09,1]]
set longMonth=%_imonthf
set shortMonth=%_imonth
date %saveDate
return

the attach batch lets you try it

Andre
 
Andre Arpin wrote:
| Getting the name for a month should be a simple function like @months
| @monthl for the short name and the long name. But it is not available
| this sub willl do it for you
|
|| getMonthName
| *set* saveDate=%_date
| *date* /f1 %@makedate[%@date[%monthRequired/1/09,1]]
| *set* longMonth=%_imonthf
| *set* shortMonth=%_imonth
| *date* %saveDate
| *return*
|
| the attach batch lets you try it

It is dangerous to change date thus, in the infrequent case saveDate is set
just before midnight, but the *date* %saveDate is executed after midnight.
you'll be a day behind. The 3 functions below, which are hereby put into the
public domain, translate between the month's ordinal number and its name
without any change in system date:

function /r << endmonthfunctions
monthf=%@word[%1,x January February March April May June July August
September October November December]
month3=%@word[%1,x Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec]
monthn=%@eval[ %@index[xxxJanFebMarAprMayJunJulAugSepOctNovDec,%@left[3,%1]]
/ 3]
endmonthfunctions

@MONTHF returns the full name, @MONTH3 the 3-letter abbreviation of the
name. @MONTHN accepts 3 characters or more, and returns the ordinal number.

To adopt the functions to any other language is trivial - just translate the
names appropriately.
--
HTH, Steve
 
Code:
monthf=%@word[%1,x January February March April May June July August 
September October November December]

month3=%@word[%1,x Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec]

If I understand correctly, he's trying to get the localized names, not necessarily English. Trivial via a plugin, but I don't see any good way to do it using just batch commands....
 
Code:
@echo off

function imonth=`%@if[%1 ge 1 .and. %1 le 12,%@winapi[kernel32.dll,GetLocaleInfo,1024,%@eval[67 + %1],buffer],]`
function imonthf=`%@if[%1 ge 1 .and. %1 le 12,%@winapi[kernel32.dll,GetLocaleInfo,1024,%@eval[55 + %1],buffer],]`

do month = 1 to 12
   echo %@format[2,%month]  %@imonth[%month]  %@imonthf[%month]
enddo
Don't even think about trying this in TCC/LE....
 
This is probably safer then mine I wish that it could be done like the day of the weeks which is

The parm being 0 is Saturday and 1 is Sunday which is nice.
function getLongDay=`%@dowf[%@eval[%1+4]]`
function getShortDay=`%@dow[%@eval[%1+4]]`


If we had something like dow and dowf for month it would be much easier.

The midnight problem could be solved but I did not bother.

You could check if you are less then 1 second before midnight and wait.
I know it is not perfect but it would be good enough.
 
This is probably safer then mine I wish that it could be done like the day of the weeks which is

The parm being 0 is Saturday and 1 is Sunday which is nice.
function getLongDay=`%@dowf[%@eval[%1+4]]`
function getShortDay=`%@dow[%@eval[%1+4]]`

...

@DOW and @DOWF are not documented to take a single number as a parameter.

I've been using this function for the full name of the day of the week for
1=Sunday ... 7=Saturday :

Code:
function @dowff=`%@dowf[2006-1-%1]`
January 2006 begins with a Sunday. If you want your day numbers to begin with Monday instead, use 2008-12-%1.
 
Charles Dye:

> Code:
> ---------
> @echo off
>
> function imonth=`%@if[%1 ge 1 .and. %1 le
> 12,%@winapi[kernel32.dll,GetLocaleInfo,1024,%@eval[67 + %1],buffer],]`
> function imonthf=`%@if[%1 ge 1 .and. %1 le
> 12,%@winapi[kernel32.dll,GetLocaleInfo,1024,%@eval[55 + %1],buffer],]`
>
> do month = 1 to 12
> echo %@format[2,%month] %@imonth[%month] %@imonthf[%month]
> enddo
> ---------

Using this code in TCSTART to build the array of local monthnames used in
the functions I posted would do an excellent job. Even better, if one uses
global functions, one could build the functions using a transient instance
of TCC during log-in, and let SHRALIAS.EXE save them for all work instances.
--
HTH, Steve
 
Back
Top
[FOX] Ultimate Translator
Translate