Robert
Robert

Reputation: 4406

How do I get the current Date in C#

I am using the Reporting feature in Visual Studio and I need to create a prop/variable to store the current date so I can display it on my form. I cannot seem to find the proper way to do this in the report view.

I originally tried a property of :

public DateTime CurrentDate {get;}

This did not work because there is no setter for it. To fix the problem I :

public DateTime CurrentDate{get{return DateTime.Now;}}

Thanks for the suggestions. They lead me in the right direction.

Upvotes: 0

Views: 2409

Answers (4)

Tim B James
Tim B James

Reputation: 20374

For the Date only, I would use

DateTime.Today

or

DateTime.Now.Date

Upvotes: 1

Brandon Poole
Brandon Poole

Reputation: 372

System.DateTime.Now. to get string format:

System.DateTime.Now.ToString()

Upvotes: 0

Aghilas Yakoub
Aghilas Yakoub

Reputation: 29000

You can try with this code

DateTime.Now

You can specify format

DateTime.Now.ToString("yourFormat")

Msdn : http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx

Upvotes: 1

Related Questions