Solved

convert stirng to date

Posted on 2009-07-13
3
296 Views
Last Modified: 2012-06-27
RIGHT(String, 10)

will result in this: 'DD-MM-YYYY'

how do i convert this to an integer with 'YYYYMMDD' format?
0
Comment
Question by:Amien90
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 21

Expert Comment

by:Tapan Pattanaik
ID: 24837990
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 24838029
try this

Declare @str varchar(20)
set @str = '13-07-2007'

select  Cast ( Right(@str,4) + substring(@str,4,2)+Left(@str,2)  as int)
select  Right(@str,4) + substring(@str,4,2)+Left(@str,2)  
0
 
LVL 27

Expert Comment

by:Zberteoc
ID: 24846290
here is much simpler:

select convert(varchar, convert(datetime, '27-07-2009',105), 112)

The result even varchar can be asigned to integer columns or variables aand even directly used in arithmetic expressions. If you still need integer you can cast it:

select cast(convert(varchar, convert(datetime, '27-07-2009',105), 112) as int)


PS. I know was already answered but I didn't like the solution. :o)
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Following an example - removing duplicate strings 4 70
Bubble user-defined Sql RAISERROR(...) to c# exception 14 228
How to simplify my SQL statement? 14 61
Format Date fields 11 63
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question