I just caught myself about to do this:

  • Language: C#

    Goal: Strip the timestamp off for a midnight comparison

    Auto pilot: DateTime.Parse(DateTime.Now.ToShortDateString())

    What I should actually have done: DateTime.Today

    It's going to be one of those days.

  • SockDev

    if it's any help i spend about 40% of my professional life in C# and i still forget about DateTime.Today about once a month...

  • No Date.Parse(DateTime.Now.ToShortDateString)?

  • SockDev

    @chubertdev said:

    No Date.Parse(DateTime.Now.ToShortDateString)?

    wouldn't Date.Parse(DateTime.Now+"") work just as well if you are going that route? IIRC the time string provided to Date.parse can contain time information but the time information would be ignored.

  • But it's not as WTF-ery as mine.

  • SockDev

    i dunno. i like the "random" string concatenation in there for mine. to the inexperienced eye it looks like something might be up with that.

    what about Date.Parse(DateTime.Now+"".Trim())

  • Date.Parse((DateTime.Now.ToUniveralTime()+System.Environment.NewLine).Trim())


  • SockDev

    we can make it WTFier!

    we have the technology!

    i wonder how we could get XML in there for extra enterprise goodness?

  • Call out to the database, of course.

    select cast('<DateAtMidnight>' + CONVERT(varchar(50), getdate(), 101) + '</DateAtMidnight>' as XML)

  • Discourse touched me in a no-no place

    Ah, but you have to remember that it's against corporate policy to host a database on the same system as front-end code.

    SOAP call to a date-computation-service. Locate it with UDDI for bonus enterpriseyness.

  • @accalia said:

    i wonder how we could get XML in there for extra enterprise goodness?

    XSLT to perform the time truncation?

Log in to reply

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.