Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,
I want to display yesterdays date using label

The date must be in this format (DDMMYY)

so, it should display in label as 171212

I need in Asp.net c# using Label.

So that I can display in my project with label as Last modified at 171212


Please help Thanks.
Posted

Try it, Perfectly working
C#
string yday=string.Empty;
        yday = DateTime.Now.AddDays(-1).ToString("ddMMyy");
        Label1.Text = yday;


Thanks
 
Share this answer
 
Comments
Ranjith Reddy CSE 19-Dec-12 1:55am    
Thank you very Much.......
DateTime.Now.AddDays(-1).ToString("ddMMYYYY"); The casing may be wrong, but that's about it.

This is really both basic and widely documented, I'd be concerned that you could not work it out, but you're using ASP.NET.
 
Share this answer
 
Comments
AshishChaudha 19-Dec-12 1:55am    
I am sorry for this but not giving the proper result. It should be DateTime.Now.AddDays(-1).ToString("ddMMyyyy");
Christian Graus 19-Dec-12 1:58am    
As I said, the casing may be wrong.
maybe it could help you :
C#
DateTime yesterdayDate = DateTime.Now.AddDays( -1 );
Label1.Text = yesterdayDate.ToString(); 
 
Share this answer
 
Comments
Ranjith Reddy CSE 19-Dec-12 1:45am    
sir, it is displaying todays date.
I need Yesterdays date....Please help. Thanks
[no name] 19-Dec-12 1:47am    
make it -2..
Ranjith Reddy CSE 19-Dec-12 1:49am    
ok i got it with -2 ....
But i need in this format 171212. Please help
[no name] 19-Dec-12 1:51am    
for that you can use,
http://msdn.microsoft.com/en-us/library/system.string.remove(v=vs.71).aspx
Christian Graus 19-Dec-12 1:58am    
If it shows todays date, it's because it's tomorrow on the server.
try this
C#
string YesterdayDate= DateTime.Now.AddDays(-1).ToString("ddMMyy");
        Label1.Text = YesterdayDate;

hope this will solve your problem.
 
Share this answer
 
v2

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