Date Functions – SQL Server vs MySQL

Continuing my series on how same things can be done differently in SQL Server and MySQL, in this post, we will see some Date Functions in SQL Server and MySQL. I have put them in a table format so that it becomes easier for you to follow:
 
SNo Purpose SQL Server MySQL
1 Find out current date and time Getdate() now()
2 Find out day name of current date datename(weekday ,getdate()) Dayname(now())
3 Find out day of month datename(day,getdate()) dayofmonth(now())
4 Find out day of week datepart(weekday,getdate()) dayofweek(now())
5 Find out day of year datepart(weekday,getdate()) dayofyear(now())
6 Find out year value year(getdate()) year(now())
7 Find out month value month(getdate()) month(now())
8 Find out day value day(getdate()) day(now())
9 Find out last day of month eomonth(getdate()) last_day(now())
10 Find out month name datename(month,getdate()) monthname(now())
11 Find out Time value from seconds cast(dateadd(second,seconds_value,0) as time) sec_to_time(seconds_value)
12 Subtract days from date dateadd(day,-day_value,getdate()) date_sub(now(), interval day_value day)
13 Add days to date dateadd(day,day_value,getdate()) adddate(now(), interval day_value day)
13 Get UTCDATE GETUTCDATE () UTC_TIMESTAMP()
14 Format a date (dd-mm-yyyy) format(getdate(),'d-MM-yyyy') DATE_FORMAT(now(), '%d-%c-%Y');
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章