How to get datetime from both date and time fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • getmeidea
    New Member
    • Feb 2007
    • 36

    How to get datetime from both date and time fields

    Hi all,

    I have a table,
    account_transac tions(trans_rid int primary key COMMENT 'Transaction ID',
    trans_date date COMMENT 'Date of transaction',
    trans_time time COMMENT 'Time of transaction')

    I need a query which returns me two fields "Transactio n ID" and "Transactio n Date" time.

    The "Transactio n Date" should be of type datetime(using both trans_date and trans_time).
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by getmeidea
    Hi all,

    I have a table,
    account_transac tions(trans_rid int primary key COMMENT 'Transaction ID',
    trans_date date COMMENT 'Date of transaction',
    trans_time time COMMENT 'Time of transaction')

    I need a query which returns me two fields "Transactio n ID" and "Transactio n Date" time.

    The "Transactio n Date" should be of type datetime(using both trans_date and trans_time).
    Your table design was wrong then. You should have stored one field with the DateTime type as explained in the refmanual here.

    Comment

    • getmeidea
      New Member
      • Feb 2007
      • 36

      #3
      Originally posted by r035198x
      Your table design was wrong then. You should have stored one field with the DateTime type as explained in the refmanual here.
      Yes, I know this is not the right way of designing. But it was already made.
      Here i need the solution with query.

      Comment

      • mwasif
        Recognized Expert Contributor
        • Jul 2006
        • 802

        #4
        You can CONCAT_WS() both the fields to get date and time e.g.

        [CODE=mysql]SELECT trans_rid, CONCAT_WS(' ', trans_date, trans_time) AS Transaction_Dat e FROM account_transac tions;[/CODE]

        Comment

        Working...