I need to convert the system datetime to timestamp in script task SSIS.
input date format: 29/05/2010 2:开发者_运维技巧36 AM
output format: 29-15-2010 14:36:00
thanks prav
The output doesn't quite match the input (the month becomes 15, and it goes from AM to PM). I assume those are typos. It should be something like:
string output = DateTime.ParseExact(input, "dd/MM/yyyy h:m tt", null).ToString("dd-MM-yyyy HH:mm:ss");
If it's user input, you may want TryParseExact
instead.
Givig the format of output into the string method gives the timestamp results.
string dt = DateTime.Now.ToString("yyyy'-'MM'-'dd' 'HH':'mm':'ss");
DateTime dateformat = Convert.ToDateTime(dt);
Console.WriteLine(dt);
Console.WriteLine(dateformat);
Console.ReadLine();
thanks prav
DateTime.Parse(input).ToString("dd-MM-yyyy HH:mm:ss")
精彩评论