-2

Can somebody help me with my report view problem. I need to view monthly organization report. I do get the report for one month but the problem is it didn't take the first day of the month as the initial. from the day the report has been generate, it is just count 30 days backward. therefore it will take the report for the previous month too since it didn't start from 1 day of every month. this is the code that i used.

SELECT *
FROM aduan_form
WHERE tarikh >= SUBDATE(SYSDATE(), INTERVAL 30 DAYS)

i know there is something wrong with it, i already try to add the format in sysdate() which is :

SELECT *
FROM aduan_form
WHERE tarikh >= SUBDATE(SYSDATE('%Y-%m-01'), INTERVAL 1 MONTH)

but the result still the same. how can i fix this problem?

brenjt
  • 15,997
  • 13
  • 77
  • 118
nur
  • 9
  • 1

1 Answers1

0

For Oracle, this would help:

Oracle, Make date time's first day of its month

@MatBailie said: According to http://psoug.org/reference/date_func.html, this should work a dandy...

SELECT TRUNC(yourDateField, 'MONTH') FROM yourTable
Community
  • 1
  • 1
  • Thank you for the info, but i need the code for php. – nur May 20 '15 at 04:29
  • The example provided should help you. I don't tried this: SELECT * FROM aduan_form WHERE tarikh >= TRUNC(SYSDATE(), 'MONTH') –  May 20 '15 at 07:08
  • still it retrieve the data from the previous month along with the current month data as long as it still in the range of 30 days. – nur May 20 '15 at 13:10