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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:43:00+00:00 2026-05-28T04:43:00+00:00

I have a database script that returns date time string and my problem is

  • 0

I have a database script that returns date time string and my problem is that I don’t know what format my string will be. The reason is that I have desktop in different culture and they could return any kind of format. My ultimate goal is, from the string to return the DateTime.
As I am trying to write something I am realizing that I would need to try any kind of format to make sure something comes back to me without an exception.
There should be a better way to do this without trial and error.
This is what I have but it only works for a few formats:

    public static DateTime FromQueryResultString(string dttmString)
    {
        string[] formats = { "dd/MM/yyyy", "yyyy-MM-dd HH:mm:ss", "dd/MM/yyyy HH:mm:ss", "yyyyMMdd HH:mm:ss", "dd.MM.yy hh:mm", "M/d/yy h:mm tt", "ddd MMM dd H:mm:ss yyyy", "dd.MM.yy hh:mm", "dd.MM.yy HH:mm","ddd MMM yy H:mm:ss yyyy" };

        string name = Thread.CurrentThread.CurrentCulture.Name;
        IFormatProvider format = new CultureInfo(name, false);
        DateTime formattedDate = DateTime.ParseExact(dttmString, formats, format, DateTimeStyles.None);
    }
  • 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-28T04:43:01+00:00Added an answer on May 28, 2026 at 4:43 am

    I think you’re missing a fundamental concept.

    Considering that you’re talking about a DataBase script, it’ a script, I immagine, which returns a data from database. Your database has to always hold a DateTime, floating point numbers and other culture sencitive data in one common format. In this case, you will have one single stable Data Access Layer which will recover and manipulates data recovered from Rome, Paris, Beijing or Abu Dhabi. The client program that data will visualize in culture dependent way.

    In short: choose one format and store it in that way.

    It’s clear that this architecture is not always possible to have, but from my expirience it is possible in 99% of cases.

    Hope this helps.

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

Sidebar

Related Questions

I have a script that polls a MySQL database (Nagios, specifically) for the date/time
I have a script that parse the database and create php classes to work
I have a script that did double inserts into the database with the same
I have a script that automatically populates a mysql database with data every hour.
I have a TSQL script that is used to set up a database as
With my database upgrade scripts, I typically just have one long script that makes
I have a script that, inserts into the database e.g. 20,000 users with email
I am creating a notifications script that check a database for changes and returns
I have a string that needs to be turned into a date attribute to
I have the following code that will count the elapsed time and print the

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.