473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Need help how to do Time format in MySql

hi all,


I have time stored in my table field as hh:mm am or pm (eg 04:15 PM , 02:30 AM). The field is of type varchar.

I need to convert it as a MySql time format.

Can any body help me...Please .. Its urgent
Jun 20 '07 #1
6 3741
r035198x
13,262 8TB
hi all,


I have time stored in my table field as hh:mm am or pm (eg 04:15 PM , 02:30 AM). The field is of type varchar.

I need to convert it as a MySql time format.

Can any body help me...Please .. Its urgent
If you're using MySQL 5 or higher you can use the str_to_date function. Otherwise you'd have to do it outside the database.
Jun 20 '07 #2
pbmods
5,821 Expert 4TB
Here are your options for pre-5 MySQL:
http://dev.mysql.com/doc/refman/4.1/...functions.html

And for MySQL 5:
http://dev.mysql.com/doc/refman/5.0/...functions.html
Jun 22 '07 #3
Hi,

Thanks for your suggestion. I have already seen the link provided by you. But could get idea which funtion and forma to use..

I am using Mysql version 5.1.

Can u tell me the exact function format to get my required result. I need to generate the report based on ascendin order of time.

Since my time field is of varchar type, i am getting the display is String order not in the actual time order what i need.. Thats what i need to convert the varchar format to time format.

Please help me.. My work is pending because of this..

Looking forward for your help at the earliest..




Here are your options for pre-5 MySQL:
http://dev.mysql.com/doc/refman/4.1/...functions.html

And for MySQL 5:
http://dev.mysql.com/doc/refman/5.0/...functions.html
Jun 25 '07 #4
date_format(str_to_date('12:24 am','%h:%i %p'),'%T')
returns 00:24:00

date_format(str_to_date('01:24 pm','%h:%i %p'),'%T')
returns 13:24:00
Jun 25 '07 #5
to just order your result set right, you could use something like this
(even in older mysql versions)

say your time field is named "clock"...

Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.           (clock LIKE '%pm%') as t ,  *
  3. FROM   tbl
  4. ORDER BY  clock,t
  5.  
this would just add a virtual column t, containing:
- 0 where clock doesn't contain 'pm' (where clock is am)
- 1 where clock contains 'pm'

so you order your set by clock, and then t
Jun 25 '07 #6
Hi i have used this format function
date_format(str_to_date(starttime,'%h:%i %p'),'%T')

which gave me the required result.


Thanks a lot for your valuable help. Thank you once again.

date_format(str_to_date('12:24 am','%h:%i %p'),'%T')
returns 00:24:00

date_format(str_to_date('01:24 pm','%h:%i %p'),'%T')
returns 13:24:00
Jun 25 '07 #7

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

Similar topics

12
by: Rick | last post by:
I need to store a date prior to the unix epoch, any pointers? -- Rick Digital Printing www.intelligence-direct.com
1
by: Neal | last post by:
I have a MySQL table with a datetime field that stamps the time the user submitted the form. It works and looks like this: $sql = "INSERT INTO table VALUES(....now())"; On another php page to...
1
by: Dave Posh | last post by:
I seem to be having a problem displaying time stored in mysql. The format stored in the database is 13:15:05. The database data type is time. I'm using asp vbscript and sql to retrieve the time...
3
by: parksch2 | last post by:
I have been trying and trying to properly sort records through a mySQL query. I have hour, minute and AM/PM values stored separately in a database as varchars. I'm trying to concat those, cast them...
2
by: phillip.s.powell | last post by:
I have to migrate data from one database table to another table in another database where the fields do not match, not even in the same order, and even if they do match, on occasions the datatypes...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
9
by: Paul | last post by:
I have a process that I want to speed up. It first was written in Microsoft Access then converted to VB.NET. I would like to hear some suggestions on how to speed it up. The process is to match...
5
by: rouven | last post by:
Hi, i am trying to convert that time format '05:26:40 Jun 19, 2007 PDT' into mysql compatible format like YYYY-MM-DD HH:MM:SS. the code i tried was: from datetime import datetime from time...
2
by: daknightuk | last post by:
Hi people, I'm working on a project where I have a MYSQL database containing a database table which has opening hours of a load of businesses in it. Each business has 4 TIME fields for each day...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.