Click here to Skip to main content
15,900,815 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Team,

I know the format to get the DateTime.
for example:
DateTime dt = DateTime.Now;
i will get Date and Time.

But if i want date like 28-dec-1980
how to get it ?

Kindly help

Thanks
Harshal
Posted
Comments
[no name] 11-Feb-14 2:33am    
class Program
{
static void Main(string[] args)
{
DateTime objDateTime = new DateTime();
objDateTime = DateTime.Now;
Console.Write("Today Date And Time is " +objDateTime.ToString());
Console.ReadLine();
}
}

I have tried this..

 
Share this answer
 
Comments
[no name] 11-Feb-14 2:39am    
Thanks Buddy..
Krunal Rohit 11-Feb-14 2:40am    
Glad I could Help
-KR
[no name] 11-Feb-14 3:16am    
One help Please.
i just tried out .
class Program
{
static void Main(string[] args)
{
DateTime objDateTime = new DateTime();
objDateTime = DateTime.Now;
string format = "dd-yyyy-mm";
Console.Write("Today Date And Time is " +objDateTime.ToString(format) );
Console.ReadLine();
}
}
But i am not getting month in Jan,Feb .... format.Kindly tell me where i am getting wrong?
C#
using System;

class Program
{
    static void Main()
    {
    DateTime time = DateTime.Now;              // Use current time
    string format = " dd-MMM-yyyy";    // Use this format
    Console.WriteLine(time.ToString(format));  // Write to console
    }
}
 
Share this answer
 
Comments
[no name] 11-Feb-14 2:53am    
Thank you brother.
[no name] 11-Feb-14 3:16am    
i just tried out .
class Program
{
static void Main(string[] args)
{
DateTime objDateTime = new DateTime();
objDateTime = DateTime.Now;
string format = "dd-yyyy-mm";
Console.Write("Today Date And Time is " +objDateTime.ToString(format) );
Console.ReadLine();
}
}
But i am not getting month in Jan,Feb .... format.Kindly tell me where i am getting wrong
[no name] 11-Feb-14 3:43am    
You have used wrog dateformat... use string format = " dd-MMM-yyyy";
[no name] 11-Feb-14 5:35am    
ok.i correct it but in month i want like Jan ,Feb ...and so on..
[no name] 11-Feb-14 5:44am    
paste your code here... i will correct it
C#
class Program
   {
       static void Main(string[] args)
       {
           string teststring = "abcdefgha";
           DateTime date = DateTime.Now;
           string datetime1 = date.ToShortDateString();
           string datetime2 = date.ToLongDateString();
            string datetime3 = date.ToString("dd-MM-yyyy");
           Console.Write(datetime1);
           Console.Write(datetime3);

           Console.ReadKey();
       }
   }
 
Share this answer
 
v2
Comments
[no name] 11-Feb-14 2:58am    
thanks for your reply.
[no name] 11-Feb-14 3:15am    
i just tried out .
class Program
{
static void Main(string[] args)
{
DateTime objDateTime = new DateTime();
objDateTime = DateTime.Now;
string format = "dd-yyyy-mm";
Console.Write("Today Date And Time is " +objDateTime.ToString(format) );
Console.ReadLine();
}
}
But i am not getting month in Jan,Feb .... format.Kindly tell me where i am getting wrong
[no name] 11-Feb-14 3:20am    
month will be capital letter MM

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