How I can convert “02 August 2012 18:53” to DateTime?
when I use StrToDate for convert it occur error ‘Invalid Date format’
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
VarToDateTime(found in theVariantsunit), which supports various time formats Delphi’s RTL doesn’t. (It’s based on COM’s date support routines like the ones used in various Microsoft products.) I tested with your supplied date, and it indeed converts it to aTDateTimeproperly. Tested on both Delphi 2007 and XE2.More info in the current documentation , including another sample of use (link at the bottom of that page).
Note the function in
Variantsunit use the default user locale. If it is not ‘US’ the conversion from the above string might fail. In that case you would better callVarDateFromStrdirectly fromactivexunit specifying the US locale: