Click here to Skip to main content
15,888,047 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i got the date from queryString as
08102013223300---->date month year hours minutes seconds

how to form date as year-month-date hour:minute:seconds

2014-10-08 22:33:00
Posted

C#
DateTime.Now.ToString("tt HH:mm:ss ") 
 
Share this answer
 
string dateString = "08102013223300";
string format = "ddMMyyyyHmmss";

DateTime dateTime = DateTime.ParseExact(dateString, format,
    System.Globalization.CultureInfo.InvariantCulture);

textBox1.Text = dateTime.ToString("yyyy-MM-dd H:mm:ss");
 
Share this answer
 
Comments
Member 10263519 1-Feb-14 3:09am    
thanks a lot it's working
Refer - How to convert Javascript datetime to C# datetime?[^].
You can form one Date String according to your requirement and pass that in QueryString.

Then parse that in C#.
 
Share this answer
 
Comments
Member 10263519 1-Feb-14 2:45am    
from my device i got the datetime as 08102013223300

but i need to place in mysql table as 2013-10-08 22:33:00

how to do that.
As I said you have to change the Date string in JavaScript and of that.

Anyway, it seems that you have that with help of Peter's answer. :)
Try this:

C#
string result = DateTime.ParseExact(inputstring, "ddMMyyyyHHmmss").ToString("yyyy-MM-dd HH:mm:ss");


I'm pretty sure that works, but I haven't tried it myself.
Hope this helps :-)
 
Share this answer
 
v2
Comments
Member 10263519 1-Feb-14 2:48am    
am getting error as no overloaded method with 1 parameter
Mitchell J. 1-Feb-14 3:49am    
Of course! Silly me, I forgot a variable. I updated my answer.

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