Posted on 2007-07-30
Last Modified: 2007-07-30
Using Sybase ASE 12.5.4 and I need to parse a datetime entry into a date and time column separately, separately.  I am currently using the datename function to build a string for each column, as seen below:
(date is a datetime field)
datename(mm,'/'+datename(dd,'/'+datename(yy, as Date',
datename(hh,':'+datename(mi,':'+datename(ss, as 'Time',
Is there a cleaner and more efficient way of doing this?
Question by:mynus482
    1 Comment
    LVL 19

    Accepted Solution

    I believe so.

    You can use the convert function with the correct STYLE specifier and get what you want directly.

    .... convert(,1) as DateCol,
         convert(,8) as TimeCol

    The style number specifiers are documented in the T-SQL Reference Manual: Building Blocks.

    Style 1 converts to MM/DD/YY and Style 8 converts to HH:MM:SS, both of which are what I believe you were specifying above.

    BTW, storing dates and times as strings greatly reduces their utility in the database.  Sorting order is all wrong, date math is out of the question unless you are willing to write very complex and inefficient expressions that convert the strings back to dates first.  Since you can always get the strings out of dates or, better yet, datatime datatypes, the best practice rule of thumb is to store them as such rather than as strings.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data storage…
    I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    758 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

    11 Experts available now in Live!

    Get 1:1 Help Now