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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:03:19+00:00 2026-05-25T12:03:19+00:00

I am comparing the time now to a time stored somewhere in a database.

  • 0

I am comparing the time now to a time stored somewhere in a database. The time stored in the database is in the format of “yyyyMMddHHmmss”. For example, the database may return 201106203354 for a stored time value. I am then using a function to compare the time now to the time read in from the database.

What I am doing now:

  1. Create 6 int variables
  2. Take the sub-string from the formatted date string and convert the sub-string to an int32.
  3. Pass the 6 int variables to the function.

What I would like to do:

Rather than splitting up the formatted date-time string, and seperately creating and assigning six variables to pass to the function, I would like to know if there is some way to simply convert the formatted date-time string into DateTime.

Please see my code as it will help to explain what I clearly cannot …

Pass time now along with time read from database:

Private void passTime()
{
            string timeStamp;
            int year, month, day, hour, minutes, seconds;

            DateTime dt = DateTime.Now;

            timeStamp = dt.ToString("yyyyMMddHHmmss");

            year = Convert.ToInt32(timeStamp.Substring(0, 4));
            month = Convert.ToInt32(timeStamp.Substring(4, 2));
            day = Convert.ToInt32(timeStamp.Substring(6, 2));
            hour = Convert.ToInt32(timeStamp.Substring(8, 2));
            minutes = Convert.ToInt32(timeStamp.Substring(10, 2));
            seconds = Convert.ToInt32(timeStamp.Substring(12, 2));

            MessageBox.Show(GetDifferenceDate(
                            new DateTime(year,month,day,hour,minutes,seconds),
                            // Example time from database
                            new DateTime(2011, 08, 11, 11, 40, 26)));
}

static string GetDifferenceDate(DateTime date1, DateTime date2)
        {
            if (DateTime.Compare(date1, date2) >= 0)
            {
                TimeSpan ts = date1.Subtract(date2);
                return string.Format("{0} days",
                    ts.Days);
            }
            else
                return "Not valid";
        }

So, quite simply, I would like to compare two dates that are both in the format of “yyyyMMddHHmmss”, or if this is not possible, I would like to convert the previous Date string into a DateTime.

I’m sure I left something out here, I will go back and read it again but please feel free to ask me anything that I left unclear.

Thank you,
Evan

  • 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-25T12:03:20+00:00Added an answer on May 25, 2026 at 12:03 pm

    You’re looking for ParseExact:

    DateTime.ParseExact(timeStamp, "yyyyMMddHHmmss", CultureInfo.InvariantCulture)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In using Stopwatch.GetTimestamp() we find that if you record the return value and then
I'm compiling some C# and VB code at run time using the CodeDomProvider, CompilerInfo,
I am doing some research into methods of comparing time series data. One of
I've been trying to build some huge projects in BCB5 for some time now.
I seem to be getting run-time errors in my project when using javac for
I've been using binding frameworks for a while now and i'd like to know
I have some time defined from my database, and this is how it looks:
I have developed a simple Apache-Axis java web service using Eclipse IDE and now
As I know, an array needs to have a specific size before compiling time
Compiling a C++ file takes a very long time when compared to C# and

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.