Delphi : Date and Time Format from ddd-mm-yy to mm/dd/yyyy

i had a case a few weeks back of a problem where the computer needs to have a date format of dd-mmm-yy which in today’s date is 21-Feb-18. What i need is for the program to act the same as it was with the format 02/21/2018.

After digging data, i came across these gems of a find. It’s so short and so obvious, i hope this code can help somebody out

Enjoy

Coffee Cup

 

 

 

{
CurrencyString, CurrencyFormat, NegCurrFormat, ThousandSeparator,
DecimalSeparator, CurrencyDecimals, DateSeparator, ShortDateFormat,
LongDateFormat, TimeSeparator, TimeAMString, TimePMString,
ShortTimeFormat, LongTimeFormat

//Change COMPUTER date and time
SetLocaleInfo(GetThreadLocale, LOCALE_SSHORTDATE, ‘MM/dd/yyyy’);
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0,
SMTO_ABORTIFHUNG, 1000, PDWord(Nil)^);

//Change formatting from within the APPLICATION
DateSeparator := ‘/’;
ShortDateFormat := ‘MM/dd/yyyy’;

SetLocaleInfo(DefaultLCID, LOCALE_SSHORTDATE, ‘m/d/yy’) (short form) and
SetLocaleInfo(DefaultLCID, LOCALE_SLONGDATE, ‘mmmm d, yyyy’) (long form)

SetLocaleInfo(GetThreadLocale, LOCALE_SSHORTDATE, ‘MM/dd/yyyy’);
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0,
SMTO_ABORTIFHUNG, 1000, PDWord(Nil)^);
}

// Change the display formatting
DateSeparator := ‘/’;
ShortDateFormat := ‘MM/dd/yyyy’;

Leave a Reply

Your email address will not be published. Required fields are marked *