If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Concat + time_format???

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-25-11, 14:55
fr0s1yjack fr0s1yjack is offline
Registered User
 
Join Date: Apr 2011
Posts: 21
Concat + time_format???

hi,

i need to concat two columns aswell as perform a time_format on them, struggling with syntax, heres what i have:

SELECT CONCAT(stf.forename, ' ', stf.surname) AS Name, DATE_FORMAT(shf.shift_date,'%b %d %Y') as Date,
TIME_FORMAT(CONCAT(shf.start_time, '-', shf.end_time, '%H - %i %p')) as Shift
FROM staff stf, shift shf, staff_shift ss
WHERE shf.shiftID = ss.shiftID

im getting the error

"Incorrect parameter count in the call to native function 'TIME_FORMAT'"

returned

please help!!!
Reply With Quote
  #2 (permalink)  
Old 05-25-11, 16:52
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
Have a look at your second TIME_FORMAT function:

SELECT CONCAT(stf.forename, ' ', stf.surname) AS Name, DATE_FORMAT(shf.shift_date,'%b %d %Y') as Date,
TIME_FORMAT(CONCAT(shf.start_time, '-', shf.end_time), '%H - %i %p') as Shift
FROM staff stf, shift shf, staff_shift ss
WHERE shf.shiftID = ss.shiftID
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #3 (permalink)  
Old 05-25-11, 17:14
fr0s1yjack fr0s1yjack is offline
Registered User
 
Join Date: Apr 2011
Posts: 21
thanks for the reply!

i've got a result, which is great however the two 'times' are failing to concatenate in the column
Reply With Quote
  #4 (permalink)  
Old 05-25-11, 18:58
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
what datatypes are the start_time and end_time columns? could we see sample values?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 05-26-11, 09:53
fr0s1yjack fr0s1yjack is offline
Registered User
 
Join Date: Apr 2011
Posts: 21
the 'start_time and end_time are both 'TIME' datatypes, example entries would be 09:00:00 and 21:00:00
Reply With Quote
  #6 (permalink)  
Old 05-26-11, 12:50
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
oh, i see

could you please explain what you were trying to do here...

Code:
TIME_FORMAT(CONCAT(shf.start_time, '-', shf.end_time), '%H - %i %p') as Shift
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 05-26-11, 17:27
fr0s1yjack fr0s1yjack is offline
Registered User
 
Join Date: Apr 2011
Posts: 21
the two columns need to be concatenated, its to display a shift for someone. Rather than have it displayed as 'start_time 09:00:00' as one column and 'finish_time 21:00:00' as another, i thought it would be be better for the end user user to be able to read it as just 'Shift 9:00 am - 9:00pm' (24 hour format is a possible alternative)
Reply With Quote
  #8 (permalink)  
Old 05-26-11, 17:34
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
okay, i understand

try this --
Code:
SELECT CONCAT(stf.forename,' ',stf.surname) AS Name
     , DATE_FORMAT(shf.shift_date,'%b %d %Y') as Date
     , CONCAT(TIME_FORMAT(shf.start_time,'%h:%i %p')
             ,' - '
             ,TIME_FORMAT(shf.end_time),'%h:%i %p')
             ) AS Shift
  FROM ...
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 05-26-11, 17:45
fr0s1yjack fr0s1yjack is offline
Registered User
 
Join Date: Apr 2011
Posts: 21
r937, ever a legend!! it works! thank you so much!!

just to tie it up there was one bracket missing..

SELECT CONCAT(stf.forename,' ',stf.surname) AS Name
, DATE_FORMAT(shf.shift_date,'%b %d %Y') as Date
, CONCAT(TIME_FORMAT(shf.start_time,'%h:%i %p')
,' - '
,TIME_FORMAT((shf.end_time),'%h:%i %p')
) AS Shift
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On