Click here to Skip to main content
14,545,215 members
Rate this:
Please Sign up or sign in to vote.
See more:
Quote:
Hi,
I am using asp.net with c# and Sql server as database.
I would like to know todya is which day either Monday or Tuesday or Wednesday and so on For getting today date time I am using System.DateTime.Now.ToString(). Please help me.


What I have tried:

Quote:
System.DateTime.Now.ToString()
Posted
Updated 22-May-20 20:06pm

1 solution

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

Solution 2

Don't convert everything to a string - keep them as their original type until you need to display data to the user.
Try this:
DateTime now = System.DateTime.Now;
Console.WriteLine(now.DayOfWeek);
The DayOfWeek property[^] returns a DayOfWeek enum[^], which gives Sunday as 0, Monday as 1, ... and which converts to a "human readable" version when converted to a string.
   

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