Solved

Date Conversion

Posted on 2007-04-02
4
305 Views
Last Modified: 2012-06-21
Hi,

I’m using SQL Server 2000. I have a table called Status with a column name StatusStartDate (smalldatetime).  In my Status table; the date appears as 6/1/2007, but when I do a select statement, my output looks like 2007-06-01 00:00:00.

My syntax is as follows:

Declare @Month int
Declare @Year varchar(4)
Set @Month='6'
Set @Year='2007'
declare @StatusStartDate smalldatetime
Select @StatusStartDate=Convert(smalldatetime,StatusStartDate,101) from qryVerifyStatus where MonthNumberStartDate=@Month and Year=@Year
Select @StatusStartDate

Question:
How do I create a smalldatetime format mm/dd/yyyy for the StatusStartDate column?
The Convert(smalldatetime,StatusStartDate,101)  did not do the job.

Thanks,
Denise

0
Comment
Question by:DeniseGoodheart
[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
  • 2
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 480 total points
ID: 18839750
the FORMAT is a display issue, hence the result is a string (varchar), and not a date:

Declare @Month int
Declare @Year varchar(4)
Set @Month='6'
Set @Year='2007'
declare @StatusStartDate varchar(10)
Select @StatusStartDate=Convert(varchar(10),StatusStartDate,101) from qryVerifyStatus where MonthNumberStartDate=@Month and Year=@Year
Select @StatusStartDate
0
 

Author Comment

by:DeniseGoodheart
ID: 18839897
angelll:

Thanks for the clarificarication.  What happens if I want to do a date comparison between a date parameter that was passed by a stored procedure as dd/mm/yyyy and one that I retrieved within my stored procedure such as
Select @StatusStartDate=StatusStartDate from qryVerifyStatus where MonthNumberStartDate=@Month and Year=@Year

Question:My @StatusStartDate output is 2007-06-01 00:00:00 and my stored procedure parameter is 6/1/2007.  Would I be able to do a date comparision?

Thanks,
Denise
0
 
LVL 11

Assisted Solution

by:dready
dready earned 20 total points
ID: 18839915
what i use to cut off the time part is:
select (convert(datetime,convert(char(8),getdate(),112)))

but this is a european date format. You might have to do something like
 select (convert(datetime,convert(char(8),getdate(),101)))

0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 480 total points
ID: 18839947
>Question:My @StatusStartDate output is 2007-06-01 00:00:00 and my stored procedure parameter is 6/1/2007.  Would I be able to do a date comparision?

if the procedure parameter is of data type datetime, yes.
if not, you should first convert the procedure parameter or it's value to datetime.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

632 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