Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9162975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:20:23+00:00 2026-06-17T14:20:23+00:00

I am using an Informix database. I want to get the difference between two

  • 0

I am using an Informix database. I want to get the difference between two dates, and the data type of return value must be an integer. The SQL looks like:

select (today - to_date('20121201','%Y%m%d'))  from your_table_name

However, when I execute the SQL it returns 45 and certainly the computed value is not the integer type.
What’s the date type of the value? How can I cast the value to integer?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:20:24+00:00Added an answer on June 17, 2026 at 2:20 pm

    The TO_DATE function is an Oracle import, and returns an Oracle DATE type in Oracle (hence the name), but the Oracle DATE type corresponds to an Informix DATETIME type. So, the Informix implementation of the TO_DATE() function returns a DATETIME type.

    Problem

    SELECT TODAY AS TODAY,
           TO_DATE('20121201', '%Y%m%d') AS raw_to_date,
           (TODAY - TO_DATE('20121201','%Y%m%d')) AS raw_difference
      FROM sysmaster:informix.sysdual;
    
    today       raw_to_date                   raw_difference
    DATE        DATETIME YEAR TO FRACTION(5)  INTERVAL DAY(8) TO DAY
    2013-01-16  2012-12-01 00:00:00.00000     46
    

    Solution

    The solution for your expression is to apply the DATE function to the output of TO_DATE, or cast it to type DATE.

    SELECT DATE(TO_DATE('20121201', '%Y%m%d'))          AS date_to_date,
           CAST(TO_DATE('20121201', '%Y%m%d') AS DATE)  AS cast_to_date,
                TO_DATE('20121201', '%Y%m%d')::DATE     AS colon_to_date,
           (TODAY - DATE(TO_DATE('20121201','%Y%m%d'))) AS date_difference
      FROM sysmaster:informix.sysdual;
    
    date_to_date  cast_to_date  colon_to_date  date_difference
    DATE          DATE          DATE           INTEGER
    2012-12-01    2012-12-01    2012-12-01     46
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to connect to Informix database using sample code from https://www.ibm.com/developerworks/data/library/techarticle/dm-0510durity/ I'm using
I'm using SSIS to fetch data from two Informix servers. I'm using a Merge
We have an Informix 4GL forms interface to our database, accessed using a terminal
Using a populated Table Type as the source for a TSQL-Merge. I want to
I am using the Informix.NET driver (C#) to insert a row into a database
I try to connect to informix server 11.5 using using IBM.Data.Informix (located in C:\Program
I have 2 Informix queries that I believe should return the same data but
Using batch script, I want to get a first token of a line delimited
is there a difference in the Informix query performance using ANSI syntax: SELECT ..
Is there a way to connect to an Informix database using Sql Management studio?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.