Hi my string is as follows
string s ="20000101";
I would like to convert to Date format. How can i
Hi my string is as follows
string s ="20000101";
I would like to convert to Date format. How can i
The power of Google. There are a thousand articles and results on Google.
Putting even the minimum amount of effort into this problem would give you the answer. You must learn the skill of working things out for yourself, especially when the problem is so simple.
Assuming you are using C# and .Net you will want to use DateTime.ParseExact or DateTime.TryParseExact. The format string is most likely "yyyyMMdd".
var datestring = "20000101";
var date1 = DateTime.ParseExact(datestring, "yyyyMMdd", null);
// ... or ...
DateTime dateResult;
if (!DateTime.TryParseExact(datestring, "yyyyMMdd",
null, DateTimeStyles.AssumeLocal,
out dateResult))
dateResult = DateTime.MinValue; //handle failed conversion here
in C/C++, use the time.h (ctime) library's gmtime function, after converting the time to an integer: tm =gmtime(atoi(time_string));