Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

retrieving a part of current year in mysql [closed]

Tags:

sql

select

mysql

i want to retrieve the last two digits of current year for ex- i want to retrieve "13" from current year "2013'. help me provide a suitable query for this

Thanx

like image 501
user2071594 Avatar asked Feb 15 '13 05:02

user2071594


People also ask

How do I get this year data in MySQL?

Use the YEAR() function to retrieve the year value from a date/datetime/timestamp column in MySQL. This function takes only one argument – a date or date and time. This can be the name of a date/datetime/timestamp column or an expression returning one of those data types.

How do I get previous month records in MySQL?

Hopefully, now you can easily get last one month data in MySQL. Similarly, if you want to get records for past one month rolling, that is, last 30 days, then here's the SQL query for it. select * from orders where order_date>now() - interval 1 month; In the above query, we select rows after past 1 month interval.

How do I get the current year in SQL query?

MySQL YEAR() Function The YEAR() function returns the year part for a given date (a number from 1000 to 9999).


2 Answers

try this one

SELECT DATE_FORMAT(datefield, '%y')
like image 140
Nilesh Gupta Avatar answered Oct 05 '22 22:10

Nilesh Gupta


use DATE_FORMAT

SELECT DATE_FORMAT(CURDATE(), '%y')
  • SQLFiddle Demo
  • MySQL DATE_FORMAT()
like image 45
John Woo Avatar answered Oct 06 '22 00:10

John Woo