thefirstfbli
asked on
Sql Finding Month of Date
hi all,
i want to find a month from the table tableX which contains full_date, last_name ect...
full_date's format is like this : "1987.06.17 00:00:00"
now, i write a query like this,
SELECT full_date FROM tableX WHERE full_date LIKE '_____06%' this is works for JUNE's..
But i want to write a query like this SELECT full_date FROM tableX WHERE full_date LIKE 'JUNE' ;
how can ?
i want to find a month from the table tableX which contains full_date, last_name ect...
full_date's format is like this : "1987.06.17 00:00:00"
now, i write a query like this,
SELECT full_date FROM tableX WHERE full_date LIKE '_____06%' this is works for JUNE's..
But i want to write a query like this SELECT full_date FROM tableX WHERE full_date LIKE 'JUNE' ;
how can ?
assume your full_date is of VARCHAR2 type,
SELECT full_date from tableX where
to_char(to_date(full_date, 'YYYY.MM.DD HH24:MI:SS'), 'MM') = '06';
SELECT full_date from tableX where
to_char(to_date(full_date,
ASKER
can not use 'June', instead of integers. without using integer 06, i want to use JUNE word in the query..
Or a more simpler way:
SELECT full_date from tableX where
extract ( month from to_date(full_date, 'YYYY.MM.DD HH24:MI:SS')) = 6;
SELECT full_date from tableX where
extract ( month from to_date(full_date, 'YYYY.MM.DD HH24:MI:SS')) = 6;
If you insist to use JUNE keyword,
here is what you can do:
SELECT full_date from tableX where
to_char(to_date(full_date, 'YYYY.MM.DD HH24:MI:SS'), 'MONTH') = 'JUNE';
here is what you can do:
SELECT full_date from tableX where
to_char(to_date(full_date,
Sorry forgot to trim the space:
SELECT full_date from tableX where
trim(to_char(to_date(full_ date, 'YYYY.MM.DD HH24:MI:SS'), 'MONTH')) = 'JUNE'
SELECT full_date from tableX where
trim(to_char(to_date(full_
ASKER
should it work for this format "1987.06.17 00:00:00" .. full_date's entry is like this.Becuse it is not working. i am just trying, may there is no solution for this.
may be it will work if the entry of full_Date is like this "1987.JUNE.17 00:00:00" but know it is not working for 1987.06.17 00:00:00.. but there is no compilation fault.
may be it will work if the entry of full_Date is like this "1987.JUNE.17 00:00:00" but know it is not working for 1987.06.17 00:00:00.. but there is no compilation fault.
what is the data type for your field (full_Date) ?
assuming that it is indeed datetime (or timestamp), a simplified version of pkwan's suggestion should work:
SELECT full_date from tableX
where to_char(full_date, 'MONTH') LIKE 'JUNE%'
if it's varchar, a minor change to pkwan's code should work:
SELECT full_date from tableX
where to_char(to_date(full_date, 'YYYY.MM.DD HH24:MI:SS'), 'MONTH') LIKE 'JUNE%'
assuming that it is indeed datetime (or timestamp), a simplified version of pkwan's suggestion should work:
SELECT full_date from tableX
where to_char(full_date, 'MONTH') LIKE 'JUNE%'
if it's varchar, a minor change to pkwan's code should work:
SELECT full_date from tableX
where to_char(to_date(full_date,
ASKER
full_date is DATE.. data type..
table is like this,
full_date
1987.06.17 00:00:00
1994.02.17 00:00:00
1998.03.19 00:00:00
maybe there is no sql query to do this. i just create a problem to solve it :) really it is not a problem also.
i may write
SELECT full_date FROM tableX WHERE full_date LIKE '_____06%'
or
SELECT full_date FROM tableX WHERE month(full_date) = 6
instead of writing JULY in query... :(
table is like this,
full_date
1987.06.17 00:00:00
1994.02.17 00:00:00
1998.03.19 00:00:00
maybe there is no sql query to do this. i just create a problem to solve it :) really it is not a problem also.
i may write
SELECT full_date FROM tableX WHERE full_date LIKE '_____06%'
or
SELECT full_date FROM tableX WHERE month(full_date) = 6
instead of writing JULY in query... :(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
okk.. i got.. thanks.
SELECT full_date FROM tableX WHERE month(full_date) = 6