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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:27:49+00:00 2026-05-13T16:27:49+00:00

I’d like to construct a query to convert a postgresql datetime to a matlab

  • 0

I’d like to construct a query to “convert” a postgresql datetime to a matlab datenum. Experience with other DBs has shown me that converting the date on the DB side is much faster than doing it in matlab.

Matlab stores dates as number of days (including fractions) since an arbitrary epoch of a gregorian, non-existent date of 00-00-0000.

On Oracle, it’s simple, because Oracle stores dates internally like matlab does, but with a different epoch.

select (date_column_name - to_date('01-Jan-0001') + 365) ...

A straightforward conversion of this to PG syntax doesn’t work:

select (date_column_name - date '01-Jan-0001' + interval 365) ...

I’ve started with a particular day in matlab, for testing:

>> num2str(datenum('2010-10-02 12:00'))

ans =

734413.5

I’ve been in and out of the pg docs all day, extracting epochs and seconds, etc. And I’ve gotten close. Basically this gets the seconds in an interval, which I just divide by the seconds in a day:

Select cast(extract(epoch from (timestamp '2010-10-02 12:00' 
                               - timestamp '0000-01-01 23:10'
                               + interval '2 day'
                               )
                   ) as real
           )/(3600.0*24.0)  AS MDate

answer:
734413.51111111111

But that exhibits some bizarre behavior. Adjusting the minutes from the epoch timestamp doesn’t change the answer, except at one particular minute – i.e 23:09 is one answer, 23:10 is another, and it stays the same from 23:10 to 23:59. (other hours have similar behavior, though the particular “minute” is different.)

Any ideas? Maybe on another way to do this?

edit:
using 8.4.2

  • 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-13T16:27:49+00:00Added an answer on May 13, 2026 at 4:27 pm

    It seems that the cast was the problem.

    Select extract(epoch from (timestamp '2010-10-02 12:00:01' 
           - timestamp '0000-01-01 00:00' 
           + interval '1 day'))/(3600.0*24.0)
    

    works like a champ.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I know there's a lot of other questions out there that deal with this
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has

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.