Solved

Date Conversion

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

809 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