QuestionQ160

VerifiedData Manipulation

A developer extracts a date from an email. The date will always follow the same format and will always be from the past. Examples of this format include “3 Mar 2023” and “20 Nov 2021”. The variable that stores the date is named DateString. Which expression should the developer use to check whether the extracted date is within the last 7 days?

Explanation

The d MMM yyyy custom format accepts both one- and two-digit day values, including 3 Mar 2023, while InvariantCulture consistently parses the English abbreviated month name. Subtracting the parsed past date from DateTime.Now produces a positive TimeSpan; a Days value below 7 indicates an elapsed interval of fewer than seven whole days.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!