Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: Change format Day with Leading zero In DateTime

Tags:

c#

in C#, DateTime.Day.Now.ToString() is returning 1. How can i get it as 01?

like image 340
Shyju Avatar asked Apr 01 '10 17:04

Shyju


2 Answers

Two quick methods

DateTime.Now.Day.ToString("00"); DateTime.Now.ToString("dd"); 
like image 108
Anthony Pegram Avatar answered Sep 21 '22 14:09

Anthony Pegram


Try this:

DateTime.Now.Day.ToString("00"); 
like image 28
Andrew Hare Avatar answered Sep 25 '22 14:09

Andrew Hare