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

  • Home
  • SEARCH
  • 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 6092063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:23:59+00:00 2026-05-23T12:23:59+00:00

The following line of code return true (which it should not)….and convert 1.0228 into

  • 0

The following line of code return true (which it should not)….and convert 1.0228 into datetime…

DateTime.TryParse(1.0228,out temporaryDateTimeValue)

Somebody please help me.

  • 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-05-23T12:23:59+00:00Added an answer on May 23, 2026 at 12:23 pm

    The following line of code return true (which it should not)….and convert 1.0228 into datetime…

    DateTime.TryParse(1.0228,out temporaryDateTimeValue)
    

    This will not compile.

    However, if you wrap it in quotes (and clean it up a little bit),

    bool success = DateTime.TryParse("1.0228", out temporaryDateTimeValue);
    

    then, yes, you will get true back. You need to read the documentation to understand why, but basically, there are many different ways to format dates and you stumbled on one (maybe M.yyyy?).

    If you don’t want it to parse, may I suggest

    bool success = DateTime.TryParseExact(
                       "1.0228",
                       "yyyyMMdd", 
                       CultureInfo.InvariantCulture,
                       DateTimeStyles.None,
                       out temporaryDateTimeValue
                   );
    

    Then success is false.

    I note from the remarks in the documentation:

    The string s is parsed using formatting information in the current DateTimeFormatInfo object, which is supplied implicitly by the current thread culture.

    This method tries to ignore unrecognized data, if possible, and fills in missing month, day, and year information with the current date. If s contains only a date and no time, this method assumes the time is 12:00 midnight. Any leading, inner, or trailing white space character in s is ignored. The date and time can be bracketed with a pair of leading and trailing NUMBER SIGN characters (‘#’, U+0023), and can be trailed with one or more NULL characters (U+0000).

    Because the DateTime.TryParse(String, DateTime) method tries to parse the string representation of a date and time using the formatting rules of the current culture, trying to parse a particular string across different cultures can either fail or return different results. If a specific date and time format will be parsed across different locales, use the DateTime.TryParse(String, IFormatProvider, DateTimeStyles, DateTime) method or one of the overloads of the TryParseExact method and provide a format specifier.

    Basically, TryParse "tries" very hard to parse the string you give it (although the "Try" really refers to the fact that the method returns a bool for success/failure indication).

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

Sidebar

Related Questions

I have the following line of code for a Windows forms application: return Encoding.ASCII.GetBytes(chars.ToArray());
Could anyone please explain the following line of code, found on http://docs.openttd.org/ai__cargo_8cpp_source.html return (AICargo::TownEffect)::CargoSpec::Get(cargo_type)->town_effect;
I thought the following line of code should work fine: $(.1).attr('href', '#Home'); Right? But
Why wouldn't the following line of code work in a method? return (count >
The following line of code generates the compile time error (PE19) There is no
The following line of code is causing me an Exception using (new INVU.API.CallContextStore()) {
The following line of code causes my program to break in a very strange
I have the following line of code: public bool dcpl_radar() { if (radar ==
I have the following line of code called very often: var configValue = System.Configuration.ConfigurationManager.AppSettings[ConfigValueKey];
I added following line of code in .vimrc let g:jslint_status = 'enabled' if exists(jslint_status)

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.