Exam UiADPv1 All QuestionsBrowse all questions from this exam
Question 103

A developer extracts a date from an email. The date will always be in the same format and always from the past. Some examples of this format are: “3 Mar 2023”, “20 Nov 2021”. The name of the variable where the date is saved is DateString. What expression should the developer use to check if the extracted date is within the last 7 days?

    Correct Answer: C

    To determine if the extracted date is within the last 7 days, the developer needs to correctly parse the date string and then calculate the difference in days between the current date and the extracted date. The format 'd MMM yyyy' ensures proper parsing of both '3 Mar 2023' and '20 Nov 2021'. The expression (DateTime.Now - DateTime.ParseExact(DateString, “d MMM yyyy”, Cultureinfo.InvariantCulture)).Days < 7 accurately evaluates if the date is within the last 7 days.

Discussion
EricHsuOption: C

C is the correct, the formate "d MMM yyyy" can pass throw the both case the sentence give. test by the studio

ramziothmaneOption: C

C is the correct one because for this case 3 Mar 2023 its in format "d MMM yyyy" otherwise it should be 03 Mar 2023

kingkayyOption: A

B - subtracts 7 days from the difference between the dates, which isn't a requirement C - 'dd' for day in the format string. But here it is just a 'd' D - subtract a string (DateString) from a DateTime object would not work.

AndresPCOption: A

A is the correct one