Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8831155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:14:55+00:00 2026-06-14T08:14:55+00:00

Came across a curious problem. In our code the other day. I’ve come up

  • 0

Came across a curious problem. In our code the other day. I’ve come up with a quick fix, but I couldn’t help wondering if there was a better way of doing it.

The problem comes when parsing the string values submitted via QueryString into typed objects that eventually end up in a SQL stored procedure. For most eventual comparison types, comparing strings is fine, but to do “less than” or “greater than” and the like with dates, the string has to be converted to a date first.

So we were doing this – value is submitted into the function as a string after being pulled out of the querystring:

if (DateTime.TryParse(value, out newTime))
{
    value = newTime.ToStringIsoUtc();
}

return value

Which worked fine for years, until someone tried to submit a three-part version number. Suddenly 1.3.1 became 2001-03-01 and the comparison stopped working.

My quick fix was just to check to see if there was more than one dot in the potential “date” and if so, leave it as a string. Easy. But the trouble is that while none of our clients currently use anything other than UTC date format, I got scared when I looked on Wikipedia and found how many countries use something like dd.mm.yy as a standard date format.

Is there a better way of telling an untyped version number from a date?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:14:57+00:00Added an answer on June 14, 2026 at 8:14 am

    There is no way that you can do this with just the date value alone. What you really need is another value indicating what the format of the DateTime in the querystring is.

    Take for example your 1.3.1 format. Who is to say that it’s not really able to be interpreted as January 3rd, 2011 (looking at it from left-to-right as opposed to right-to-left).

    You have two options:

    • If you want a completely open value, you need a hint indicating how it should be interpreted (which you would use to adjust your call to set the options in the call to DateTime.TryParse), along with the caveat that if the hint is not provided, then the results may be indeterminable when the input is ambiguous

    • Reject anything that isn’t in the expected format.

    The first is preferable when dealing with user input, as you want to make it as easy as possible for your users and lower the bar to entry.

    Note that if the user input is coming from say, a web page that uses HTML 5, you should be aware that the input tag allows for date and datetime input types. Not only does this have the benefit of allowing browsers to provide standardized (at least, across a platform) way of inputting this type of data, but it also provides for standardizing the format that data is transmitted in, meaning your input falls more into #2 than it does in #1.

    The second is preferable when When dealing calls made from APIs, as the DateTime instances (or representations of them) can be modified to fit your expectations (since they have a strongly typed representation in memory already before calling your API).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across this due to a bug in my code and I'm curious
I came across code similar to the following today and I am curious as
I realise this code is faulty. However, I came across some curious behaviour which
I came across this problem while preparing for an interview and curious to know
I came across with a curious situation when using jamod to write to modbus.
Came across this code: <?php require_once 'HTTP/Session/Container/DB.php'; $s = new HTTP_Session_Container_DB('mysql://user:password@localhost/db'); ini_get('session.auto_start') or session_start();
Came across a problem whereby I wanted the last time data was imported to
I came across this Linq to Sql code in an application I am maintaining:
I came across a piece of code which looks like this: jQuery(function($) { $('#saySomething').click(function()
I came across the below lines in code unsigned char A = 0xB9; unsigned

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.