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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:57:45+00:00 2026-05-27T22:57:45+00:00

The year is given as int : 2009, 2010 etc. I want to convert

  • 0

The year is given as int: 2009, 2010 etc.
I want to convert this information to DATE (first January).

My solutions (I prefer the first one):

(year::char || '-01-01')::DATE
'0001-01-01' + ((year-1)::char || ' year')::interval

Is there a better (build in) or more elegant and faster solution?
(I’m currently working with PostgreSQL 8.4 but are also interested in more recent versions.)

  • 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-27T22:57:46+00:00Added an answer on May 27, 2026 at 10:57 pm

    I think this is the simplest way:

    to_date(year::varchar, 'yyyy')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I get the start and end date of a given year (int),
I am using this method to convert a month and year to a date
For example: Data Given : Year-2010, Month-2, Fortnight-1 Current date How do I get
I need to convert a given date to an int containing the number of
Given data frame values are Group year Value A 2010 17 A 2011 18
Is there a way to, given a date, retrieve the season of the year?
I want to calculate the week number of a given date. DateTime date =
I'm trying to create a Date like this: date = new Date(year-1900, mon-1, day,
My SQL table looks like this: id (int) | date (date) | text1 (varchar)
I want to select records that have a created date between the first and

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.