Calculating the Date from Exported PostgreSQL Table

Posted by Johan Cyprich on 14 Dec 2009 | Tagged as: Programming

When exporting a PostgreSQL database to another database server, such as MySQL or MS SQL Server, the date field will appear as a number if it is saved as an Excel sheet. After spending some time trying to determine what the number means, I found that it seems to represent the number of days from January 1, 1900.

The problem is that when I test the date with the C# code below, the actual date in the database is off by 2 days. This may be the result of the original PHP application not calculating the date correctly from the Postges database. I doubt that Postgres would have the first entry of the date field starting on January 3, 1900.


int iDays = 39970;          // number of days since January 1, 1900

DateTime StartTime = new DateTime (1900, 1, 1);
DateTime EndTime = StartTime.AddDays (iDays);

Console.WriteLine (EndTime.ToString ());



Tweet This Tweet This Post!

Related posts:
    Fixing PostgreSQL Services With Clean Install
    Updating PostgreSQL With yum
    Postgres: column “field” does not exist
    Fixing “/var/lib/pgsql/data is missing” Error

Share this post:

del.icio.us:Calculating the Date from Exported PostgreSQL Table digg:Calculating the Date from Exported PostgreSQL Table spurl:Calculating the Date from Exported PostgreSQL Table wists:Calculating the Date from Exported PostgreSQL Table simpy:Calculating the Date from Exported PostgreSQL Table newsvine:Calculating the Date from Exported PostgreSQL Table blinklist:Calculating the Date from Exported PostgreSQL Table furl:Calculating the Date from Exported PostgreSQL Table reddit:Calculating the Date from Exported PostgreSQL Table fark:Calculating the Date from Exported PostgreSQL Table blogmarks:Calculating the Date from Exported PostgreSQL Table Y!:Calculating the Date from Exported PostgreSQL Table smarking:Calculating the Date from Exported PostgreSQL Table magnolia:Calculating the Date from Exported PostgreSQL Table segnalo:Calculating the Date from Exported PostgreSQL Table gifttagging:Calculating the Date from Exported PostgreSQL Table

Follow Me:

Did you find this post interesting and useful? You can keep up to date on this blog by subscribing to my RSS feed, or you can have new posts sent to you by e-mail. You can also follow me on Twitter.


Trackback This Post | Subscribe to the comments through RSS Feed

Leave a Reply

CommentLuv Enabled