Solved

SyBase SQL DataTime Format

Posted on 2014-03-08
6
291 Views
Last Modified: 2014-03-15
Sybase SQL Anywhere v10

I am using CONVERT(VARCHAR(20),t1.timeord, 100) and I get "Mar 07 2014 05:06PM"

I want shortened date and I need the seconds as well. 03/07/14 05:06:19PM

Thanks in advance.
0
Comment
Question by:triphen
  • 3
  • 3
6 Comments
 
LVL 26

Expert Comment

by:wilcoxon
ID: 39915388
Assuming convert is the same between ASE and SQL Anywhere (100 is the same at least):

convert(varchar(20),t.timeord,1)+' '+convert(varchar(20),t.timeord,14)
gives you 03/07/14 17:06:19 (24-hour clock)

convert(varchar(20),t.timeord,1)+' '+convert(varchar(20),t.timeord,36)
gives you 03/07/14 05:06:19.000000PM (eg includes microseconds)

Oddly, I can't find any format that gives you exactly what you want.
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 39915390
It looks like SQL Anywhere is a little different.  Checking the ref docs, 36 isn't listed and 14 includes the microseconds.  I'd suggest giving both my suggestions in my previous post a try and see if they work (and if they include the microseconds).

If it is important to remove microseconds, that can be accomplished by calling some other functions.
0
 

Author Comment

by:triphen
ID: 39916743
select convert(varchar(20),timeord,1)+' '+convert(varchar(20),timeord,36) from dba.posdetail

Returns

03/07/14 2014-03-07 21:37:10.


select convert(varchar(20),timeord,1)+' '+convert(varchar(20),timeord,14) from dba.posdetail

Returns

03/07/14 21:37:10:079



Looks like both are 24 hour mode. I need 12 hour AM/PM with hour, minute, and seconds.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 26

Assisted Solution

by:wilcoxon
wilcoxon earned 500 total points
ID: 39917739
Seems like there's no easy way to do that.  Here's the best I can come up with:

convert(varchar(20),timeord,1)+' '+
case when datepart(hh,timeord)=0 then '12:'+convert(varchar(2),datepart(mi,timeord))+':'+convert(varchar(2),datepart(ss,timeord))+'AM'
when datepart(hh,timeord)>12 then convert(varchar(2),datepart(hh,timeord)-12)+':'+convert(varchar(2),datepart(mi,timeord))+':'+convert(varchar(2),datepart(ss,timeord))+'PM'
else convert(varchar(2),datepart(hh,timeord))+':'+convert(varchar(2),datepart(mi,timeord))+':'+convert(varchar(2),datepart(ss,timeord))+'AM'
end

Open in new window

0
 

Accepted Solution

by:
triphen earned 0 total points
ID: 39918183
I actually got it with this.

select convert(varchar(20),timeord,1) || right(convert(varchar(20),timeord,9),9) || right(convert(varchar(30), timeord, 9),2) from dba.posdetail

Thank you so much!
0
 

Author Closing Comment

by:triphen
ID: 39931102
Less code for the same result.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle TEXT search question 9 48
SyBase Query Syntax Date Time conversion 4 27
How does this SELECT query work 11 100
Updating a table from a temp table 4 28
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now