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

  • Home
  • SEARCH
  • 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 3979378
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:09:47+00:00 2026-05-20T05:09:47+00:00

I am wondering how I would loop through a datetime or any type of

  • 0

I am wondering how I would loop through a datetime or any type of variable to go from 12:00AM to 11:59PM every 30 Mins?

So I need a variable that shows times in 12HR format (01:00PM, 09:00AM) and everytime I loop through it, to add 30 mins to the time? I then need to use this value in a string.

The time needs to start at 10:00AM

  • 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-20T05:09:47+00:00Added an answer on May 20, 2026 at 5:09 am

    And there is always LINQ

    var start = DateTime.Today;
    var clockQuery = from offset in Enumerable.Range(0, 48)
                     select start.AddMinutes(30 * offset);
    foreach (var time in clockQuery)
        Console.WriteLine(time.ToString("hh:mm tt"));
    

    … LINQ + FUNC (for parameterized start)

    Func<DateTime, IEnumerable<DateTime>> clockQuery = start =>
        from offset in Enumerable.Range(0, 48)
        select start.AddMinutes(30 * offset);
    foreach (var time in clockQuery(DateTime.Today))
        Console.WriteLine(time.ToString("hh:mm tt"));
    

    … or if you just want the TimeSpan offsets …

    var start = DateTime.Today;
    var clockQuery = from offset in Enumerable.Range(0, 48)
                     select TimeSpan.FromMinutes(30 * offset);
    foreach (var time in clockQuery)
        Console.WriteLine((start + time).ToString("hh:mm tt"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering would I still need to use a basic game loop for
Am wondering if there would be any security flaw in this approach. I am
I am using while(matcher.find()) to loop through and retrieve things from a file. I
I was wondering if its possible, to loop through an array but have each
I was wondering if its possible, to loop through an array but have each
As the title says I am wondering if it is possible to loop through
I am trying to loop through an array of products. I was wondering if
Hey I was just wondering if there is a cool one liner that would
i was wondering what would be the best way to code a browser plugin
I was just wondering which would be cheaper, using a try catch block for

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.