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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:45:03+00:00 2026-05-26T14:45:03+00:00

I have written a small function in C# which isn’t my main launguage so

  • 0

I have written a small function in C# which isn’t my main launguage so is coming across a little foreign to me.

public bool CheckForKey(string key)
{
    string strKeyTime = Decode(key);
    //valid key will be current time +- 5 minutes
    string strTheTime = DateTime.Now.ToString("HH:mm:ss tt");

    if (strKeyTime == strTheTime)
    {
        return true;
    }
    else
    {
        return false;
    }
}

I need to alter this to allow for 5 minutes, so
if (strKeyTime == strTheTime)
needs to be
if (strKeyTime == strTheTime + or – 5 minutes)

my problem is matching the times as they are strings, perhaps convert key(original time) back to a date first and then do it, but I am pretty new to c#

  • 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-26T14:45:03+00:00Added an answer on May 26, 2026 at 2:45 pm

    If you convert (or keep) them both to DateTimes you can use TimeSpan:

    TimeSpan delta = dateTime1 - dateTime2;
    if (Math.Abs(delta.TotalMinutes) <= 5) { ... }
    

    Look into using the DateTime.ParseExact (or any of the Parse… methods) to parse your strKeyTime, and then do something similar to the above.

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

Sidebar

Related Questions

I have written a small function, which uses ElementTree and xpath to extract the
I have written a small program which uses function pointers to do some numerical
I have written a small java application for which I need to obtain performance
I have written a small test program in which I try to use the
I have written a small GUI with qtdesigner and python which should display in
I have written a small application which will be used in my work environment
I have written some code in which a small part of the code takes
I have written a small piece of code which handles the input of a
I have an application which is written in C and logs my function calls
I have written a small jQuery plugin with the following structure: (function($) { //

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.