Solved

Date Conversion

Posted on 2007-04-02
4
295 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

739 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