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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:19:10+00:00 2026-05-13T19:19:10+00:00

if i have a datetime string in a weird format, such as YYYY##MM##DD HH**M**SS

  • 0

if i have a datetime string in a weird format, such as YYYY##MM##DD HH**M**SS, how can i create a new datetime object base on that? i have read something about the datetimeformatinfoclass but not sure how to get it working..

  • 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-13T19:19:10+00:00Added an answer on May 13, 2026 at 7:19 pm

    You can use DateTime.ParseExact, or DateTime.TryParseExact for data which you’re not confident in. For example:

    using System;
    
    class Test
    {
        static void Main()
        {
            string formatString = "yyyy'##'MM'##'dd' 'HH'*'mm'*'ss";
            string sampleData = "2010##02##10 07*22*15";
            Console.WriteLine(DateTime.ParseExact(sampleData,
                                                  formatString,
                                                  null));
        }
    }
    

    The quotes in the format string aren’t strictly necessary – this will work too:

    string formatString = "yyyy##MM##dd HH*mm*ss";
    

    However, using the quotes means you’re being explicit that the characters between the quotes are to be used literally, and not understood as pattern characters – so if you changed “#” to “/” the version using quotes would definitely use “/” whereas the version without would use a culture-specific value.

    The null in the call to ParseExact means “use the current culture” – in this case it’s unlikely to make much difference, but a commonly useful alternative is CultureInfo.InvariantCulture.

    It’s unfortunate that there’s no way of getting the BCL to parse the format string and retain the information; my own Noda Time project rectifies this situation, and I’m hoping it’ll make parsing and formatting a lot faster – but it’s far from production-ready at the moment.

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

Sidebar

Related Questions

I have a datetime object, for which I want to create a date string
I have a DateTime object that I need to print in a custom gridlike
I have an datetime object that I want to remove one hour to display
This is very weird. I have the following code: Assert.AreEqual(new DateTime(2000, 1, 1), DateTime.ParseExact(2000,
I have this: Dim myTemp As String myTemp = System.DateTime.Now().ToString(MMMddyyyy_HHmmss) & .pdf System.IO.File.Copy(myFile, c:\
I have a datetime coming back from an XML file in the format: 20080916
I have a DateTime class and wish to display it according to some format...
I have a DATETIME field. I would like to select all the records that
I have a DateTime column row and I declare a date string: Row: 2010-08-27
The string I want to format looks like this: String datetime = 9/1/10 11:34:35

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.