Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 21st, 2010, 08:12 PM
markvan markvan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 2 markvan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 59 sec
Reputation Power: 0
Extract 12hour AM/PM time from a date field

The data is stored as a date like this : 2011-02-07 19:00:00

I need to extract it like this : 7:00 PM

I've tried DATETIMEFORMAT() & DATE_FORMAT() these are not supported in Firebird.

I'm wondering if anyone has built a way to handle this with CASE statements as it seems to be something that would be needed quite often.

I can get it to display as 19:00
using left(cast(start_date AS TIME),5) as "start"

Any suggestions?

Reply With Quote
  #2  
Old November 21st, 2010, 09:23 PM
markvan markvan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 2 markvan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 59 sec
Reputation Power: 0
I worked it out, this is how:

Code:
SELECT
date,
CASE
     WHEN cast(left(cast(end_date AS TIME),2) AS INTEGER)>12
     THEN cast(cast(left(cast(end_date AS TIME),2) AS INTEGER)-12 AS VARCHAR(2)) || cast(right(left(cast(end_date AS TIME),5),3) AS VARCHAR(3))||'PM'
     ELSE cast(cast(left(cast(end_date AS TIME),2) AS INTEGER) AS VARCHAR(2)) || cast(right(left(cast(end_date AS TIME),5),3) AS VARCHAR(3))||'AM'
END as "Time",
event
FROM EVENTS


This pulls the relevant characters out of the date, convert them to integers so it can do the calculations, then converts it to varchar so it can concatenate the text. Yes it is long-winded but it works.

Enjoy

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > Extract 12hour AM/PM time from a date field

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap