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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:48:37+00:00 2026-06-07T17:48:37+00:00

I’m relatively new to SQL, so please forgive me if this is a dumb

  • 0

I’m relatively new to SQL, so please forgive me if this is a dumb question. I’ve been trying for too long now to get this to work.

I have a column in table A that is a float column called ConstructionYear. It is populated with a simple 4 digit year (i.e. 2010, 2005, 1972, etc.). I need to populate table B’s YearBuilt datetime field using these years. I’ve searched and searched and tried all sorts of different combinations of convert() and cast() that I’ve found online, but it’s not working.

What I would like to happen is this:

‘2008’ -> ‘2008-01-01 00:00:00.000’

‘2005’ -> ‘2005-01-01 00:00:00.000’

‘1986’ -> ‘1986-01-01 00:00:00.000’

Instead of what is currently happening (using CAST(ConstructionYear AS DATETIME)):

‘2008’ -> ‘1905-07-02 00:00:00.000’

‘2010’ -> ‘1905-07-04 00:00:00.000’

‘1984’ -> ‘1905-06-08 00:00:00.000’

EDIT: Solution: cast(convert(varchar,@ConstructionYear) AS DATETIME)

So my problem had 2 main causes (other than me being new to sql).

  1. I didn’t know about the 1900 epoch that SQL Server uses for datetime. I could tell something was going on because of all teh 1905 datetimes i saw, but i didn’t know that it was taking my 2005 year and counting it as days from 1900.

  2. The year 1753. Why is 1753 the earliest year we can use? I probably had the right syntax at some point before i posted my question here, but it didn’t run because my data had some years predating 1753. I assumed the error was with my code.

  • 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-07T17:48:39+00:00Added an answer on June 7, 2026 at 5:48 pm

    Check this example:

    DECLARE @ConstructionYearas FLOAT
    SET @ConstructionYear = 2012
    SELECT FloatToDatetime = CAST(convert(varchar(4),@ConstructionYear) as datetime)
    

    It will output:

    2012-01-01 00:00:00.000


    Basically use:

    CAST(convert(varchar(4),@ConstructionYear) as datetime)

    where @ConstructionYear is your Float variable

    Hope it helps!

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported

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.