I believe DateTime objects always represent valid points in time (for example, this FAQ says "DateTime objects represent exact instants in time (down to the nanosecond resolution)"), and so don't have a concept of "this field isn't set" (with the exception of the time zone, where the "floating" zone is kind of like "unset").

I am checking at a position where the date has been converted to DateTime object.

No chance you can do this before? Update: What I'm saying is that it'd probably be best if you apply these defaults yourself, sometime between where the user enters the data, like detecting the difference between "2017-06-16" and "2017-06-16T00:00:00", or applying the defaults just before you create the DateTime object.

Update 2: Another thought: I am guessing that this is some kind of system where you are asking the user to enter a date and optionally time for the end of some period, and if the user only enters a date then you assume it's the end of the day on that date? You could adjust the user interface to be more in line with the concept that the period ends at an exact time, like defaulting the user input mask to 23:59:59, or perhaps adding a radio button that makes the input look something roughly like "End Time: __/__/____ (x) at the end of this day (midnight) or ( ) on this day at this time: __:__:__".


In reply to Re: Detecting whether DateTime object has a time component or not? (updated) by haukex
in thread Detecting whether DateTime object has a time component or not? by perlancar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.