Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A few things to think about:</p> <ul> <li>"Is date x earlier than 3 months before today" isn't the same as "today is more than 3 months later than date x"; you'll need to make sure you have the exact semantics you want.</li> <li>Consider what you want to do with the time component - are you interested in <em>dates</em> or dates <em>and times</em>? (Would you expect the condition evaluation to change based on the current time of day?)</li> <li>Consider time zones: are you interested in "today in the system's current time zone" or some fixed time zone?</li> <li>Depending on the source of the text data, you should <em>possibly</em> use <code>DateTime.TryParse</code> and you should <em>possibly</em> use <code>DateTime.ParseExact</code> or <code>DateTime.TryParseExact</code>, passing in the expected format (and culture)</li> </ul> <p>Basically, there are various corner cases around date and time behaviour - you should explicitly think about all of these things (some of which are forced upon you if you use <a href="http://noda-time.googlecode.com" rel="noreferrer">Noda Time</a> instead of <code>DateTime</code>, btw :)</p> <p>Regarding the first point, if the idea is that you get a trial period of three months from the installation date (or something similar), that suggests you should be <em>adding</em> three months to that instead.</p> <p>I'd also change the variable name and get rid of the redundant parentheses, by the way:</p> <pre><code>DateTime installationDate = DateTime.Parse("1/5/2012 8:12:14 PM"); DateTime trialPeriodEnd = installationDate.AddMonths(3); if (trialPeriodEnd &gt; DateTime.Now) { // do something } </code></pre> <p>Assuming you're storing the installation date yourself somewhere, I would try to store it in some form which is less ambiguous - possibly even storing just a "ticks" value instead of a string. But assuming you <em>are</em> storing it yourself, you shouldn't need to use <code>TryParse</code> - it makes sense to go "bang" if you can't parse the value. I'd use <code>ParseExact</code>, probably with a <a href="http://msdn.microsoft.com/en-us/library/az4se3k1.aspx" rel="noreferrer">standard format specifier</a> of "o" (round trip).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload