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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:08:01+00:00 2026-06-11T13:08:01+00:00

I am on a simulation application and need to attach different time with each

  • 0

I am on a simulation application and need to attach different time with each record. I am storing the date and time in separate strings:

string pdate = DateTime.Now.ToShortDateString();  
string ptime = DateTime.Now.ToShortTimeString();

Now I am trying to add 5 minutes to the ptime variable (this I am doing in a foreach loop).

foreach (loaddata dl2 in lstdata)
{
  //some code
  ptime = DateTime.Now.AddMinutes(5); 
  //Results in ptime with date and time(I only need the time here)
}

UPDATE: I need to add 5 minutes to the previous time in each iteration

Suggestions please.

  • 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-11T13:08:03+00:00Added an answer on June 11, 2026 at 1:08 pm

    Do this way

    ptime = DateTime.Parse(ptime, "your string format", CultureInfo.InvariantCulture)
                    .AddMinutes(5).ToShortDateString();
    

    Problem with your code

    Store DateTime in DateTime only so you can “increment” them there itself.
    Converting from DateTime to string is easy and almost error free. But conversion from string to Dateime sometimes results in exception.

    Best is to do it this way

    DateTime ptime = DateTime.Now;
    
    // After some coding
    
    ptime = ptime.AddMinutes(5);
    

    Conversion to string should be done when you know that DateTime Format is not required like showing in UI.

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

Sidebar

Related Questions

I need to plot my simulation (which I do in a C++ application) for
In my application I have a situation where we need to capture the when
I need help on encryption/decryption on Android application. I explain the situation. I'm actually
I'm building a delphi application which does scientific simulation. It's growing in complexity &
Hi I have a situation where my application can be used for different purposes
it's my flight simulation application again. I am leaving the mere prototyping phase now
I have a situation where my C# Application need to communicate with my Php
In my iPhone application I need to upload images to a server. I don't
I am writing an application where in a certain block I need to exponentiate
At my consulting company, we use some very expensive simulation software. I need a

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.