Is there any way to split the date and time from the System::DateTime?
Now you get something like: 2012-03-01 16:12:555
Is there any to separate them?
Is there any way to split the date and time from the System::DateTime?
Now you get something like: 2012-03-01 16:12:555
Is there any to separate them?
If you have a DateTime
and you want to split it into date and time, you can use the properties Date
and TimeOfDay
:
DateTime now = DateTime::Now;
DateTime date = now.Date;
TimeSpan time = now.TimeOfDay;
But if you only want to get the string representation of the date and time, you don't need those properties. You can use ToString()
along with format strings:
String^ dateString = now.ToString("d");
String^ timeString = now.ToString("T");
One things you should remember about formatting in .Net is that it depends on the current culture. That means the result of calling ToString()
will be formatted differently on a computer with Czech culture than on a computer with American culture.
Simply create DateTime object like
Datetime test = DateTime::Now;
Then format it like this
String^ timestamp = test.ToString ("yyyy-MM-dd H:m:s");
This format is compatible with MySQL.