Solved

Date Conversion

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

685 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