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 6660581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:10:23+00:00 2026-05-26T02:10:23+00:00

I’m using the following syntax TIMESTAMPDIFF(2, CHAR(CREATED – TIMESTAMP(‘1970-01-01 00:00:00’)) where CREATED is of

  • 0

I’m using the following syntax

TIMESTAMPDIFF(2, CHAR(CREATED - TIMESTAMP('1970-01-01 00:00:00'))

where CREATED is of type TIMESTAMP and the database is DB2. The intension is to get the timestamp converted to millis from epoch. If there is a better function that would be more helpful.

Sample data:
For 2011-10-04 13:54:50 returned value is 1316613290 but actual value should be 1317732890 (got from http://www.epochconverter.com)

Query to run

SELECT TIMESTAMPDIFF(2, CHAR(TIMESTAMP('2011-10-04 13:54:50') - TIMESTAMP('1970-01-01 00:00:00'))) FROM  SYSIBM.SYSDUMMY1;
  • 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-05-26T02:10:24+00:00Added an answer on May 26, 2026 at 2:10 am

    This is the result of the fact that TIMESTAMPDIFF returns an estimate of the difference between the timestamps, not the actual value, as expected.

    From the reference, page 435 (assuming for iSeries):

    The following assumptions are used when converting the element values
    to the requested interval type:

    • One year has 365 days.
    • One year has 52 weeks.
    • One year has 12 months.
    • One quarter has 3 months.
    • One month has 30 days.
    • One week has 7 days.
    • One day has 24 hours.
    • One hour has 60 minutes.
    • One minute has 60 seconds.
    • One second has 1000000 microseconds.

    And the actual calculation used is:

    seconds + (minutes + (hours + ((days + (months * 30) + (years * 365)) * 24)) * 60) * 60

    This is, for obvious reasons, inexact. Not helpful.

    This appears to be a direct consequence of the way the timestamp arithmetic results are returned.
    That is;

    SELECT                                                              
    TIMESTAMP('1971-03-02 00:00:00') - TIMESTAMP('1970-01-01 00:00:00') 
    FROM sysibm/sysdummy1        
    

    returns:

    10,201,000,000.000000         
    
    Which can be divided into:
    
    • 1 year
    • 02 months
    • 01 days
    • 00 hours
    • 00 minutes
    • 00 seconds
    • 000000 microseconds

    Which is imprecise period/duration information. While there are a multitude of situations where this type of data is useful, this isn’t one of them.

    Short answer: The exact answer cannot be correctly calculated in the database, and in fact should not.


    Long answer:

    The calculations are possible, but rather complex, and definitely not suited for in-database calculation. I’m not going to reproduce them here (look up JodaTime if you’re interested, specifically the various Chronology subclasses). Your biggest problem is going to be the fact that months aren’t all the same length. Also, you’re going to run into major problems if your timestamps are anything other than UTC – more specifically, Daylight Savings time is going to play havoc with the calculation. Why? Because the offsets can change at any time, for any country.

    Maybe you could explain why you need the number of milliseconds? Hopefully you’re using Java (or able to do so), and can use java.time. But if you’re on an iSeries, it’s probably RPG…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload

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.