Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Store Date

Author  Topic 

Sunny155
Starting Member

15 Posts

Posted - 2009-04-04 : 08:18:30
Hi, Can i input the date in datetime or smalldatetime field in mm/yyyy (06/2007) format? is it possible?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-04 : 08:30:24


declare @date varchar(7)
set @date='06/2007'
select cast(right(@date,4)+left(@date,2)+'01' as datetime)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Sunny155
Starting Member

15 Posts

Posted - 2009-04-04 : 08:34:32
Thanks!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-04 : 09:28:31
quote:
Originally posted by Sunny155

Thanks!


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

zeus2026
Starting Member

11 Posts

Posted - 2009-04-06 : 01:32:54
sir I have a problem related in this thread, I also want to convert the datehired (1/31/2009) into (1/2009), but how? sorry for this newbie question, im just only a beginner in stdying sql =( tnx..

z3us
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-04-06 : 01:40:52
use month() and year() function

Select * from..... where month(1/31/2009)<'...' and year(1/31/2009)<'...'

Regards

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled
Go to Top of Page

zeus2026
Starting Member

11 Posts

Posted - 2009-04-06 : 02:07:39
sir how about this... how can i use date diff and dateadd in this code?

SELECT EmployeeName, RIGHT(CONVERT(varchar, DateHired, 105), 7) AS Date
FROM viewEmployee
WHERE (DateHired >= '11/01/08') AND (Separated = 0) AND (DeptID < 39)
ORDER BY DateHired



--------------- how can I view all of the employee that have been reach in 5 months cotract since the day that they hired...

sorry for this newbie question.....

tnx to all master....

z3us
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-06-02 : 04:41:45
SELECT EmployeeName, RIGHT(CONVERT(varchar, DateHired, 105), 7) AS Date
FROM viewEmployee
WHERE (DateHired <= dateadd(month,-5,getdate()) AND (Separated = 0) AND (DeptID < 39)
ORDER BY DateHired

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -