1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Get the name for a month

Discussion in 'T&T - Miscellaneous' started by Andre Arpin, May 12, 2009.

  1. Andre Arpin

    Joined:
    Jun 28, 2008
    Messages:
    7
    Likes Received:
    0
    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
     
  2. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    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
     
  3. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,372
    Likes Received:
    40
     
  4. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,372
    Likes Received:
    40
    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....
     
  5. Andre Arpin

    Joined:
    Jun 28, 2008
    Messages:
    7
    Likes Received:
    0
    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.
     
  6. dcantor

    Joined:
    May 29, 2008
    Messages:
    515
    Likes Received:
    3
    @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.
     
  7. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    Charles Dye:

    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
     

Share This Page