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

am using datetimepicker to select date&time as 24 hour format(yyyy-MM-dd HH:mm:ss), and am storing that in Mysql Database,and database is showing correctly as what i selected.

but the problem is when i select that from database it is giving 12 hour format,

but i want as it is , what i entered.

How to solve it
any Suggestions.......
Posted

No, it isn't - it's giving it as a DateTime object. What is happening is that you are converting the DateTime to a string, using the default conversion for your system, which is set as 12 hour with AM / PM.

Instead of using the default formatter, you can select a specific format to convert your data - see here: Formatting a DateTime for display - format string description[^]
 
Share this answer
 
plz tag this question in MYSQL

use selection of date column as

SQL
SELECT DATE_FORMAT('2013-02-04 19:38:12', '%Y-%m-%d %H:%m:%s') as date


if ur column is 'orderdate' of table order


SQL
SELECT DATE_FORMAT(orderdate, '%Y-%m-%d %H:%m:%s') as date FROM order
 
Share this answer
 
v2
Comments
Member 10263519 26-Feb-14 5:19am    
ok,
but if i use following;

using (MySqlConnection con = new MySqlConnection(ConnectionString))
{

String query = "select DATE_FORMAT(date, '%Y-%m-%d %H:%m:%s') from acc";
MySqlCommand command = new MySqlCommand(query, con);
con.Open();
using (MySqlDataReader rdr = command.ExecuteReader())
{
if (rdr.Read())
{

DateTime t = Convert.ToDateTime(rdr["date"]);
String s = rdr["date"].ToString();

MessageBox.Show("value:" + t);
}
}
}


acc table is having only 1 column

date datetime


giving error as IndexOutofbounds exception
Could not find specified column in results: date
george4986 26-Feb-14 5:41am    
because column name doesn't specified check updated solution
Member 10263519 26-Feb-14 5:25am    
IndexOutOfRange exception at datetime t=convert.todatetime(rdr["date"])
george4986 26-Feb-14 5:34am    
try below code

using (MySqlConnection con = new MySqlConnection(ConnectionString))
{

String query = "select DATE_FORMAT(date, '%Y-%m-%d %H:%m:%s') as date from acc";
MySqlCommand command = new MySqlCommand(query, con);
con.Open();
using (MySqlDataReader rdr = command.ExecuteReader())
{
if (rdr.Read())
{

DateTime t = Convert.ToDateTime(rdr["date"]);
String s = rdr["date"].ToString();

MessageBox.Show("value:" + t);
}
}
}
Member 10263519 26-Feb-14 6:15am    
thanks alot

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