Jump to content
Tuts 4 You

PureBasic Adventures...

Sign in to follow this  
  • entries
    7
  • comments
    10
  • views
    31,065

Calendar Date Format...

Teddy Rogers

2,590 views

A query was raised last week about how to determine the calendar date format for different regions; year/month/day, day/month/year, etc. After a bit of fruitless pondering whether this could be achieved via API I decided to see if it could be done via the registry. Multiple editions of Windows support the International registry subkey and from there we can use either sShortDate or sLongDate to help us reach our goal. The operating system kindly finds and formats the calendar date in the correct regional order when the user configures their region in the Control Panel or during installation. I chose sShortDate and replaced those known registry values with the values retrieved from the SYSTEMTIME structure. Below is the example...

 
; Setup string and data sizes for storing date values...
  
DateValue.s = Space(20) : DateSize = Len(DateValue)
  
; Open registry and retrieve the local calendar/date format
  
If RegOpenKeyEx_(#HKEY_CURRENT_USER, "Control Panel\International", #Null, #KEY_READ, @DateFormat) = #ERROR_SUCCESS  
  If RegQueryValueEx_(DateFormat, "sShortDate", #Null, #Null, @DateValue, @DateSize) = #ERROR_SUCCESS

    ; Receive the local date

    GetLocalTime_(@lpSystemTime.SYSTEMTIME)
      
    ; Find registry string values and replace string values from SYSTEMTIME structure

    DateValue = ReplaceString(DateValue, "yyyy", Str(lpSystemTime\wYear))
    DateValue = ReplaceString(DateValue, "yy", Str(lpSystemTime\wYear))
    DateValue = ReplaceString(DateValue, "MM", Str(lpSystemTime\wMonth))
    DateValue = ReplaceString(DateValue, "M", Str(lpSystemTime\wMonth))
    DateValue = ReplaceString(DateValue, "dd", Str(lpSystemTime\wDay))
    DateValue = ReplaceString(DateValue, "d", Str(lpSystemTime\wDay))
      
    ; Display the date
      
    MessageBox_(#Null, DateValue, "What is the date today?", #MB_ICONQUESTION | #MB_TOPMOST | #MB_SETFOREGROUND)
  EndIf
    
  RegCloseKey_(DateFormat)
EndIf

 

If you know of a way this can be done purely by API please let me know...

 

Ted.

Todays Date.zip



0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×