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 8793155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:05:14+00:00 2026-06-13T23:05:14+00:00

On both examples I’m giving it a String like the following: 26-03-17 Dim mvarValor

  • 0

On both examples I’m giving it a String like the following: 26-03-17

Dim mvarValor As String
Dim dateVarValor As DateTime

This code snippet is throwing an exception on the TryParse:

If Not mvarValor = Nothing AndAlso DateTime.TryParse(mvarValor, dateVarValor) Then
    Return Format(dateVarValor, mvarFormat)
Else
    Return strNull
End If

The next code snippet is not throwing an exception, but a False like it should:

DateTime.TryParse(mvarValor, dateVarValor)
If dateVarValor = Nothing Then
    Return strNull
Else
    Return Format(dateVarValor, mvarFormat)
End If

Why is the first code snippet giving me an exception?

Thanks in advance!

  • 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-13T23:05:15+00:00Added an answer on June 13, 2026 at 11:05 pm

    DateTime.TryParse throws three types of exceptions

    http://msdn.microsoft.com/en-us/library/9h21f14e(v=vs.100).aspx

    you must be getting one of those. Here is the proper usage of DateTime.TryParse

    var culture = CultureInfo.CreateSpecificCulture("en-US");
    
    string parsedDateTime = null;
    
    if (DateTime.TryParse(parseMe, culture, DateTimeStyles.None, out dateResult))
    {
        parsedDateTime = dateResult;
    }
    

    this snippet will parse the datetime without throwing an exception.

    I hope this helps 🙂

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

Sidebar

Related Questions

I'm trying to create a query using the LIKE statement. Both examples below work
I have some code that does something like this (Irrelevant bits snipped): void foo(Bitmap
tell me the examples of both the iPhone development programs. 1)Standard Program and 2)Enterprise
In Apple's documentation and example code, I see lproj folders both named with the
I see both in examples when checking what env one is running in. What's
In the web I've seen examples both with <% if @showIt -%> some html
I have a problem with string to datetime conversion in SQL Server 2005. If
I have seen both examples quite a bit. Let's say you have <div class=contentHere></div>
Does something like -moz-background-inline-policy exist in Webkit? This property basically gives you the opportunity
Why would I do this: var myfunc = function() { /* code */ };

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.