Solved

Date Conversion

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

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 480 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 480 total points
Comment Utility
>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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now