*Create Date Time Function
select
getdate() as "Date"
select
getdate() as "Date"
select
CURRENT_TIMESTAMP as
"DateTime"
SELECT
{fn NOW()}
select
GETUTCDATE( )
select
dateadd(day,datediff(day,0,getdate()),0)
declare
@d datetime
set
@d=getdate()
//select datediff(seconds,@d,getdate())
select
convert(char(5),getdate(), 12)
select
datename(weekday,getdate())
select
datepart(yyyy,getdate())
select
datepart(mm,getdate())
select
datepart(dd,getdate())
//select (mm,getdate())
select
@@servername
//Use Getdate() function
SELECT
LTRIM(RIGHT(CONVERT(CHAR(26),GETDATE(),109),14)) "AM PM SECOND"
SELECT
RIGHT(CONVERT(VARCHAR(20), GETDATE(), 100),7) "TIME IN
AM&PM"
select
datediff(hour,28/10/2008,30/11/2008)
//select datediff(hh,hire_date ,getdate()) from employee
select
datename(weekday,getdate())
select
replace(convert(varchar(10),CURRENT_TIMESTAMP,103) ,'/','-')
//select dateadd(dd, 1, getdate()) – add one day
//select dateadd(mm, 1, getdate()) – add one month
//select dateadd(yy, 1, getdate()) – add one year
//Same
way you can subtract day, month or year. Just give negative value.
//select dateadd(dd, -1, getdate()) –
subtract one day
//select * from agents where replace(convert(varchar,
activation_date, 102),
'.', ”) > 19200403
select
LEFT(CONVERT(varchar, CURRENT_TIMESTAMP, 103), 10)
select
CONVERT(VARCHAR(10), GetDATE(),108) "Time
Only"
select
dateadd(month,datediff(month,0,getdate())-1,0) "LastPriviousMonth"
//select * from result where
invitiondate = getdate()
//select * from result where
invitiondate >= dateadd(day,datediff(day,0,getdate()),0) and
invitiondate
< dateadd(day,datediff(day,0,getdate())+1,0)"retrive
Current Invitiondate"
//select * from result where Convert(varchar(10),invitiondate,103) = Convert(varchar(10),getdate(),103)"retrive
Current Invitiondate"
select
datediff(day,1/12/2011,30/12/2011)"difference
between the current date and the date store"
SELECT
CONVERT(VARCHAR(10), GETDATE(), 101) AS SystemDate, LEFT(RIGHT(CONVERT(varchar, GETDATE(), 0), 8), 6)+' '+ RIGHT(CONVERT(varchar, GETDATE(), 0), 2) AS SystemTime
SELECT
CONVERT(VARCHAR(10), GETDATE(), 101) AS [SystemDate], LEFT(RIGHT(CONVERT(varchar, GETDATE(), 0), 8), 6) + ' ' + RIGHT(CONVERT(varchar, GETDATE(), 0), 2) AS [SystemTime]
select
convert(varchar(10),getdate(),105)
//select datediff(day,col,getdate())>=92
select
* from [some
table] where convert
(datetime,’1/5/2009′,103′) >= getDate()
Select
Replace(Convert(Varchar(10),GetDate(),106),' ','-')
select
convert(varchar(10),getutcdate(),101)
//string
currentdate = DateTime.Parse(DateTime.Now.ToString()).ToShortDateString();
//select * from tbltest where
TrainingDate>='"
+ currentdate + "'
select
2*3600 + 46*60 + 40
select
Len('Shri Ganesh')
select
Lower('Shri Ganesh')
select
Upper('Shri Ganesh')
select
LTrim(' Shri Ganesh')
select
LTrim('Shri Ganesh ')
select
LTrim(' Shri Ganesh ')
//SubString(character_expression, position, length)
select
SubString('Shri Ganesh',6,7)
select
replace('Think High To Achieve High','High','Low')
select
right('Think High To
Achieve High',15)
select
right('111-11-1111',4) will return 1111
select
right('222-22-2222',4) will return 2222
select
right('333-33-3333',4) will return 3333
select
right('444-44-4444',4) will return 4444
select
GetDate()
select
DatePart("day",GetDate()) will return 10.
select
DatePart("hour",GetDate()) will return 16.
select
DatePart("dayofyear",GetDate()) will return 283
select
DateAdd("day",7,GetDate()) will return 2007-10-17
select
DATEDIFF("mm", Getdate()-500,GETDATE()) will return 17
select
ABS(3.14)
select
ABS(-3.14)
Select Ceiling(3.14) will return 4
select
Ceiling(-3.14) will return 3.
select
Floor(3.14) will return 3
select
Floor(-3.14) will return 4
Select Round(3.14, 1) will return 3.10
select
Round(-3.17, 1) will return -3.20
select
Round(3.12345, 4) will return 3.12350
select
Round(3.12345, 3) will return 3.12300
Select power(2,3) will return 8
0 comments
Post a Comment