I want user to be able to manually enter format of the datetime fields in the program. I have Tedit component. For example if user enters 'HH:nn', then this is a valid datetime format string and all datetime components should change format property to this, but if he enters 'asd', it is not. Is there a quick way to check this, without writing my own function?
You could use the functions:
TryStrToDate
TryStrToTime
TryStrToDateTime
They try to convert a string to a date/time and if the conversion succeeds, it returns true. So there are no exceptions raised.
You can use the optional TFormatSettings parameter to define your own format.
All functions are defined in SysUtils.
But there are some date/time controls available in the VCL like TDateTimePicker and TMonthCalendar. You can use them also.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With