Lainkes 0 Posted August 25, 2022 Hello, I have a TEdit component. Now I need to check if the value is a date. (Date is not from user input, so I cannot use a dateTimePicker) I tried to use the TryStrToDate function but then I have an error. Error : [dcc32 Error] frm_xxx.pas(691): E2250 There is no overloaded version of 'TryStrToDate' that can be called with these arguments. Is there a better solution to achieve this? Thanks Lainkes Share this post Link to post
FPiette 385 Posted August 25, 2022 TryStrToDate is the way to go. The error you mention tells you that you have wrong argument type. As we don't know how you called the function, we cannot help you more. Always show the code you are using !! Share this post Link to post
Uwe Raabe 2064 Posted August 25, 2022 22 minutes ago, Lainkes said: There is no overloaded version of 'TryStrToDate' that can be called with these arguments. Let me guess. Your code looks something like this: if TryStrToDate(Edit1, theDate) then But it should be if TryStrToDate(Edit1.Text, theDate) then 1 Share this post Link to post
PaPaNi 23 Posted August 25, 2022 2 minutes ago, Uwe Raabe said: Let me guess. Your code looks something like this: if TryStrToDate(Edit1, theDate) then But it should be if TryStrToDate(Edit1.Text, theDate) then I had exactly the same guess. Share this post Link to post
Sherlock 663 Posted August 25, 2022 I wonder why you think you can't use a TDateTimePicker? Have you tried? Whence is the date if not from the user? Because anything else should already be under your total control. 1 Share this post Link to post
Lainkes 0 Posted August 25, 2022 This is my code. So I guess I miss an argument in my statement. if TryStrToDate(edtFrom.Text) then if TryStrToDate(edtFrom.Text) then Share this post Link to post
Uwe Raabe 2064 Posted August 25, 2022 21 minutes ago, Lainkes said: So I guess I miss an argument in my statement. Yes, the variable where the date is going to be stored. Share this post Link to post
PaPaNi 23 Posted August 25, 2022 The second argument is missing... should be like: if TryStrToDate(edtFrom.Text, DateVariable) then where DateVariable has a type TDateTime. Share this post Link to post
FPiette 385 Posted August 25, 2022 You can even do better to forgive some user common error: if TryStrToDate(Trim(edtFrom.Text), DateVariable) then Share this post Link to post
Sherlock 663 Posted August 25, 2022 Sorry, but @Lainkes clearly stated, the data is not entered by the user. So no focus on fixing user errors needed here. Remains the unanswered question, about the origin of the date. How did this possibly erroneous value get into the Edit in the first place? Is it from a database? Or maybe some text file? Retrieved from a web site? All of which have appropriate methods to ensure correct data types and values. Fixing the issue on the GUI is way to late. Share this post Link to post
Fr0sT.Brutal 900 Posted August 25, 2022 Don't forget locales. '10/22/2022' => OK in USA, invalid in EU Share this post Link to post
dummzeuch 1517 Posted August 25, 2022 1 hour ago, Fr0sT.Brutal said: Don't forget locales. '10/22/2022' => OK in USA, invalid in EU Welcome to date format hell. Once you go that way, you will find out that there are many more different date formats than you ever imagined and that many of them are incompatible to each other. My favourite example: US: MM/DD/YY UK: DD/MM/YY If you have the choice always go with an international standard: ISO 8601 1 Share this post Link to post
Fr0sT.Brutal 900 Posted August 25, 2022 8 minutes ago, dummzeuch said: My favourite example: US: MM/DD/YY UK: DD/MM/YY And it's fun to have '01/02/03' 🙂 Share this post Link to post