Click here to Skip to main content
15,847,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 22:31pm

1 solution

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;
Share this answer
[no name] 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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900