Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cmonth
Message
From
03/10/2009 12:31:24
 
 
To
03/10/2009 11:43:27
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Re: Cmonth
Miscellaneous
Thread ID:
01427507
Message ID:
01427517
Views:
60
>>In command window I have witten ?cmonth(date()) like this and enter return value in main vfp window current month name. example(october) but i want month and year for example(october 2009).
>>
>>How to do this?
>
>There are several things you can do here. Tore gave you the specific reply, but you should also be aware of the following:
>
  • There are several functions that return different aspects of a date; this includes day(), month(), year() (day, month, and year), dow() (dow of week), and others.
    >
  • When combining different pieces of data (in your example you wanted the month and the year), you usually convert everything to character data type. Since the year() will return a number, you convert it to text, with a function like transform(), str(), or padl().
    >
  • If you need the same format over and over again, you may want to create a user-defined function for this.
    >
  • If you want the month in another language, you may want to create a user-defined function for this. It is extremely simple; see sample code below.
    >
    >
    >* Personal cmonth() function; easy to adapt, to show the month in a different language
    >function mycmonth(tcDate)
    >do case
    >case month(tcDate) = 1
    >  return "January"
    >case month(tcDate) = 2
    >  return "February"
    >...
    >case month(tcDate) = 12
    >  return "December"
    >otherwise && For example, empty or null date
    >  return "???"
    >endcase
    >
    Deep down in my library of rarely used functions, I found this function, Month2array
    _screen.AddProperty('mymonth(12)', '')
    Local lnMonth1
    lnMonth1=0x00000038
    Declare Integer GetLocaleInfo In kernel32;
       INTEGER Locale, Integer LCType,;
       STRING @lpLCData, Integer cchData
    For lnX=0 To 11
       _screen.mymonth(lnX+1)=Chrtran(GetLInfo(0,lnMonth1+lnX),Chr(0),'')
    Endfor
    
    Procedure GetLInfo(nLocale, nType)
       Local lcBuffer,lnLength
       lcBuffer = Replicate(Chr(0), 250)
       lnLength = GetLocaleInfo(nLocale, nType, @lcBuffer, Len(lcBuffer))
    Return Iif(lnLength > 0, Substr(lcBuffer, 1, lnLength), "")
    <pre>
    ?_screen.mymonth(4)
    ?_screen.mymonth(12)
  • Previous
    Next
    Reply
    Map
    View

    Click here to load this message in the networking platform