Click here to Skip to main content
14,544,533 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am developing a online business directory using with c# and Sql server as database.

There are two column one column for shop opening time and another column for shop closing time.

I would like to do programming to show whether the shop is the open or close as per current time. for getting current
date time I am using System.DateTime.Now.ToString()
Please help me.

What I have tried:

Updated 22-May-20 21:31pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Why are you converting the time to a string? You just need the actual time values so you can compare them.
DateTime openTime;
DateTime closeTime;
Bool shopOpen;
DateTime now = System.DateTime.Now;
if (now >= openTime && now < closeTime)
    shopOpen = true;
    shopOpen = false;
0x01AA 23-May-20 9:30am
For this I prefer the short version: shopOpen= now >= openTime && now < closeTime;
Anyway a 5
Richard MacCutchan 23-May-20 9:57am
Yes, so do I. However, most people who post here are not very experienced (this person is obviously a novice), so it is better to post the longer form which makes the sense clearer. And most modern compilers will optimise it to the form you suggest.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100