Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder General » View Thread |
Messages 1 to 3 of 3 total |
Pascal-Newbie needs advice: How to check and format a date? |
Wed, Aug 29 2012 4:25 AM | Permanent Link |
Peter | Hello,
i want to convert a date (enter by a user) into a string with the following format: 'yyyymmdd' (regarding leading zeros). 01.02.2012 -> 20120101 1.2.2012 -> 20120201 I also want to check if a given date is valid. 01.12.2021 -> Valid 33.12.2021 -> Invalid At the moment, the DateTime-Functions of EWB and my Pascal-Skills are limited, so i have no idea to solve this problem. Can somebody give me clue? Thanks in advance & Greetings ... Peter -- Sorry for my weird english |
Wed, Aug 29 2012 10:05 AM | Permanent Link |
William | =?ISO-8859-15?Q?Peter_T=FCbben?= wrote:
Hello, i want to convert a date (enter by a user) into a string with the following format: 'yyyymmdd' (regarding leading zeros). 01.02.2012 -> 20120101 1.2.2012 -> 20120201 I also want to check if a given date is valid. 01.12.2021 -> Valid 33.12.2021 -> Invalid At the moment, the DateTime-Functions of EWB and my Pascal-Skills are limited, so i have no idea to solve this problem. Can somebody give me clue? ---- I assume you are asking how to validate a properly formatted entry, and not raw text? You need to validate the month as 1 <= month <= 12. You need to determine whether the year is a leap year. Once you know whether it's a leap year, you can validate the number of days in the month. I'm very new to EWB, so am not offering working code at this point. According to the language manual, there is no support for sets, so you could do something like: var validDay: Boolean; if (1 <= month) and (month <= 12) then // valid month case month of 1, 3, 5, 7, 8, 10, 12: // months with 31 days validDay := (1 <= day) and ( day <= 31); 4, 6, 9, 11: // months with 30 days validDay := (1 <= day) and (day <= 30); else if IsLeapYear( year ) then validDay := (1 <= day) and (day <= 29) else validDay := (1 <= day) and (day <= 28); end; You can write IsLeapYear with very little effort. However, if you are starting from text which may or may not be correctly formatted to represent a date, then the answer you need is much more involved. |
Wed, Aug 29 2012 11:25 AM | Permanent Link |
Peter | Hello William,
Thanks for your response! Your solution looks good (as far as I can judge ! > You can write IsLeapYear with very little effort. Here is my implementation: function IsLeapYear(Year: Integer): Boolean; begin If ( ( Year Mod 4 ) = 0 And ( Year Mod 100 ) <> 0 ) Or ( Year Mod 400 ) = 0 Then Result := True Else Result := False; end; Thanks again & Greetings ... Peter -- Sorry for my weird english |
This web page was last updated on Friday, November 1, 2024 at 07:01 PM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |