By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,569 Members | 1,394 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,569 IT Pros & Developers. It's quick & easy.

Convert Date Time Format

P: 38
Hi all,

Im have a problem here. Im using VWD 2008 (c#) and Mysql 2005. I dont know how to convert datetime data that i retrieve from mysql database to only date or time. Can anyone help me? Here is something that i tried to do.

Expand|Select|Wrap|Line Numbers
  1.  Date1.Text = Convert.ToString(reader["FunDateTime"], (MMMM d, yyyy));
  2. //"MMMM d, yyyy",
  3. Time1.Text = Convert.ToString(reader["FunTime"], (HH:mm ss tt));
  4. //"HH:mm ss tt", 
but it didnt work even when i try to put format in of reader.
Pls some one help me.

Regards,
Meshack
Oct 17 '08 #1
Share this Question
Share on Google+
3 Replies


Frinavale
Expert Mod 5K+
P: 9,731
Hi all,

Im have a problem here. Im using VWD 2008 (c#) and Mysql 2005. I dont know how to convert datetime data that i retrieve from mysql database to only date or time. Can anyone help me? Here is something that i tried to do.

Expand|Select|Wrap|Line Numbers
  1.  Date1.Text = Convert.ToString(reader["FunDateTime"], (MMMM d, yyyy));
  2. //"MMMM d, yyyy",
  3. Time1.Text = Convert.ToString(reader["FunTime"], (HH:mm ss tt));
  4. //"HH:mm ss tt", 
but it didnt work even when i try to put format in of reader.
Pls some one help me.

Regards,
Meshack
What data type is your FunTime column? DateTime?

If so you should try to retrieve it first into a DateTime object...then calling the ToString function on that.

(Please note that I'm really not great with C#, so there may be syntax errors in the following code...it's just there to give you an idea of what I'm talking about)
Expand|Select|Wrap|Line Numbers
  1. DateTime funTime = (DateTime) reader["FunTime"];
  2. Time1.Text = funTime.ToString(HH:mm ss tt));
  3.  
-Frinny
Oct 17 '08 #2

P: 38
What data type is your FunTime column? DateTime?

If so you should try to retrieve it first into a DateTime object...then calling the ToString function on that.

(Please note that I'm really not great with C#, so there may be syntax errors in the following code...it's just there to give you an idea of what I'm talking about)
Expand|Select|Wrap|Line Numbers
  1. DateTime funTime = (DateTime) reader["FunTime"];
  2. Time1.Text = funTime.ToString(HH:mm ss tt));
  3.  
-Frinny
Thanks Frinny,

Your idea is great. There is only one error that I figured out. The following code with correction. And FunTime column is DateTime object.

Expand|Select|Wrap|Line Numbers
  1. DateTime funTime = (DateTime) reader["FunTime"]; 
  2. Time1.Text = funTime.ToString("hh:mm ss tt");
Thanks again for your help.

-Meshack
Oct 21 '08 #3

Frinavale
Expert Mod 5K+
P: 9,731
Glad to have helped :)
Oct 21 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.