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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:29:11+00:00 2026-06-09T09:29:11+00:00

I have a column in a table where timestamps have been stored in VARCHAR

  • 0

I have a column in a table where timestamps have been stored in VARCHAR format, but I need to compare these against a column of DATETIME values from another table to find time intervals, so I want to either cast or convert the VARCHAR timestamps to DATETIME. However, both casting and converting are giving me problems.

The format of the VARCHAR timestamp looks like this: "29/07/2012 01:53:36 +12".

Using the query:

SELECT CAST(event_timestamp AS datetime) FROM the_table

produces ERROR: date/time field value out of range: "29/07/2012 01:53:36 +12".

Using the query:

SELECT CONVERT(datetime, event_timestamp, 131) from the_table;

produces

ERROR:  syntax error at or near ","
LINE 1: select CONVERT(datetime, event_timestamp, 131) from the_tab...
                               ^ (note: this is pointing at the first comma). 

The error with CONVERT actually happens even if you use a generic function such as getdate() for the data source. This db uses ANSI SQL-92 (or so I’m told). Could anyone please help me out with this?

  • 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-09T09:29:13+00:00Added an answer on June 9, 2026 at 9:29 am

    This seems really painful, but the following should work:

    select dateadd(hh, cast(right(tv, 3) as int),
                   CONVERT(datetime, left(tv, 10), 103)+CONVERT(datetime, substring(tv, 12, 8), 108)
                  )
    from (select '29/07/2012 01:53:36 +12' as tv) t
    

    I’ve never added datetime’s before, but this just worked on SQL Server 2008.

    Why can’t SQL Server just support a flexible notation built around yyyy, mm, mmm, dd and so on?

    The actual database is Aster Data, which is based on Postgres (as are most recent database engines). In this database, you would use to_timestamp(). See the documentation here http://www.postgresql.org/docs/8.2/static/functions-formatting.html. The call would be something like:

    to_timestamp(val, 'MM/DD/YYYY HH:MI:SS tz') -- not sure if this gets the +12
    

    There are no ANSI functions for date conversion, so each database does its own. Even string functions vary among databases (substr? substring? charindex? instr? location?), so there is no ANSI way to do this.

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

Sidebar

Related Questions

At the moment I have a column that holds timestamps as a datetime The
Sorry if this has been asked but can't find anything. I have a table
My database table have a Timestamp column named as inTime and i am using
I have a mysql table with a column of date_modified and a timestamp set
I have a 4 column table of products in template,each item in table has
Suppose I have a 2 column table (id, flag) and id is sequential. I
I'm creating a 'similar items' link table. i have a 2 column table. both
I have a table column I’m trying to expand and hide. jQuery seems to
I have a table column called post_tags within a table called posts where assigned
I have a table column where each row has one of three states, 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.