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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:17:16+00:00 2026-06-01T23:17:16+00:00

Is it possible to convert date strings from one format to another without actually

  • 0

Is it possible to convert date strings from one format to another without actually converting them to a date?

I need something like this:

string inputDateString = "01/01/2012 23:36:17.234";
string inputFormat = "dd/MM/yyyy HH:mm:ss.fff";

string ouputFormat = "yyyy/MM/dd HH:mm:ss.fff";
string outputDateString = StringDate.Convert(inputDateString,inputFormat, outputFormat);

I can obviously write a StringDate class to parse the formats, but that would seem like reinventing the wheel. The reason I can’t go first to a date is I have had numerous problems with timezones/server times, and don’t have control over the environment in which this will run. I just want to be 100% sure that the date string is just rearanged, and not messed up!

Thanks

EDIT
The output format will always be the same, however the input format could be any combination of:

Time variations:
HH:mm:ss.fff
HH:mm:ss
HH:mm

Date variations (could be more):
dd/MM/yyyy
dd/MM/yy
MM/dd/yyyy
MM/dd/yy
yyyy/MM/dd
yy/MM/dd

  • 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-01T23:17:18+00:00Added an answer on June 1, 2026 at 11:17 pm

    You should absolutely parse it first. You just need to be careful about how you parse it and format it. Just because you’ve had problems with time zones in the past doesn’t mean you should just avoid the parsing/formatting – it means you should work out what you want to do in terms of time zones. It sounds like you just want to treat the data as local. I suspect you’ll want to specify DateTimeStyles.AssumeLocal and also use the invariant culture.

    Use DateTime.ParseExact with the exact format you’re expecting (and a specific culture, probably the invariant culture), then call ToString with the output format and again, the relevant culture.

    Also note that your expecting format string isn’t correct – you’re using hh when you mean HH, and I suspect you want fff instead of mmm. Sample code:

    using System;
    using System.Globalization;
    
    public class Test
    {
        static void Main()
        {
            string inputDateString = "01/01/2012 23:36:17.234";
            string inputFormat = "dd/MM/yyyy HH:mm:ss.fff";        
            string outputFormat = "yyyy/MM/dd HH:mm:ss.fff";
    
            DateTime parsed = DateTime.ParseExact(inputDateString, inputFormat,
                                                  CultureInfo.InvariantCulture,
                                                  DateTimeStyles.AssumeLocal);
            string outputDateString = parsed.ToString(outputFormat, 
                                                      CultureInfo.InvariantCulture);
            Console.WriteLine(outputDateString); // Prints 2012/01/01 23:36:17.234
        }
    }
    

    You might also want to look into my Noda Time project, which would allow you to create a LocalDateTimePattern for each of input and output, then reuse them repeatedly.

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

Sidebar

Related Questions

Possible Duplicate: Converting string to MySQL timestamp format in php Given a date in
I have this code that converts an array of date strings from a format
I need to code a method, something like : MyClassObject convert(Class MyClass , String
Possible Duplicate: format date in c# How do I convert a date into the
Possible Duplicate: PHP: convert date format yyyy-mm-dd => dd-mm-yyyy [NOT IN SQL] Hope everyone
Possible Duplicate: PHP: convert date format yyyy-mm-dd => dd-mm-yyyy [NOT IN SQL] Right now
Possible Duplicate: Convert NSString of a date to an NSDate I need some help
I need to parse a date/time string from user input, and convert to UTC
GNU Date lets you convert date strings like so: $ date +%d %m %Y
Is it possible in javascript to convert some date in timestamp ? i have

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.