This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Select by Month of a field
i want to get the data from database whose month is 7. means
My Date format is
PostDate datetime
now i want to query..
select * from tabelname where PostDate = 7
If you are asking how to query MySQL for date objects based on month, then this may be your answer.
select * from tablename where month(PostDate) = '07';
Keep in mind this function (month()) is MySQL specific.
Related
This question already has answers here:
Convert from MySQL datetime to another format with PHP
(18 answers)
SQL date format convert? [dd.mm.yy to YYYY-MM-DD]
(3 answers)
Closed 5 years ago.
Am trying to query data from two joined tables with a date as criteria using the query below but it brings nothing, can someone please show me what I did wrong.
SELECT Journal_T.GL_ID as Akaunti
,coa_t.gl_name_vc
,SUM(Amount_NU) as YTD
FROM Journal_T
JOIN coa_t
ON journal_t.gl_id = coa_t.gl_id
WHERE CAST(date_dt AS DATE) BETWEEN '25/08/2017' AND '25/08/2017'
AND bs_category_vc='Rev'
GROUP BY coa_t.gl_name_vc
,Journal_T.GL_ID
ISO 8601 Date format would be '2017-08-26'. Try this query to see default Date format on your server:
select STR_TO_DATE("26/08/2017", '%d/%m/%Y')
Then you can convert it, for example to '%Y-%m-%d' format:
DATE_FORMAT(STR_TO_DATE("26/08/2017", '%d/%m/%Y'), '%Y-%m-%d')
I think you can try out this query :
SELECT Journal_T.GL_ID as Akaunti,coa_t.gl_name_vc,sum(Amount_NU) as YTD
FROM Journal_T
LEFT JOIN coa_t on journal_t.gl_id = coa_t.gl_id
WHERE DATE_FORMAT(date_dt,'%d-%m-%Y') BETWEEN '25/08/2017' AND '25/08/2017'
AND bs_category_vc='Rev'
GROUP by coa_t.gl_name_vc,Journal_T.GL_ID
This question already has answers here:
Select current months records mysql from timestamp column
(12 answers)
How do I select between the 1st day of the current month and current day in MySQL?
(17 answers)
Closed 9 years ago.
How can I select Current Month records from a table of MySql database??
Like now current month is January. I would like to get records of January Month, Where data type of my table column is timestamp.I would like to know the sql query.
Thanks
This query should work for you:
SELECT *
FROM table
WHERE MONTH(columnName) = MONTH(CURRENT_DATE())
AND YEAR(columnName) = YEAR(CURRENT_DATE())
Check the MySQL Datetime Functions:
Try this:
SELECT *
FROM tableA
WHERE YEAR(columnName) = YEAR(CURRENT_DATE()) AND
MONTH(columnName) = MONTH(CURRENT_DATE());
Try this query:
SELECT *
FROM table
WHERE MONTH(FROM_UNIXTIME(columnName))= MONTH(CURDATE())
This question already has answers here:
Mysql to select month-wise record even if data not exist
(2 answers)
Closed 9 years ago.
I have a table with a column date and a column ID (to keep it simple). I am doing a query to count the total and group by week
SELECT MONTH(table1.Date_1st), YEAR(table1.Date_1st), COUNT(table1.Id)
FROM table1 as table1
WHERE Date_1st BETWEEN '2013-04-01' AND '2013-07-25'
GROUP BY WEEK(Date_1st)
the problem is there is no results on specific week the result is not taken into consideration. I already try ifnull(table1.Id,0)
Try ISNULL or other NULL SQL functions:
NULL functions
ISNULL returns a 0 if the value is null.
This question already has answers here:
Find duplicate records in MySQL
(28 answers)
Closed 8 years ago.
select name, reported_at from nodes
where reported_at < curdate() or reported_at is null
group by name
Output:
name reported at
ncs-linux-test.edu 2012-03-16 18:36:03
ocdev1.net 2012-04-06 16:32:02
pinc-ctm.net NULL
With that statement, I get any results form reported at/name that are less than the current date.
What I need though is the statement to only pull out data that has a duplicate(s) with more current information.
For example:
The statement would only pull out:
ncs-linux-test.edu 2012-03-16
if there was an
ncs-linux-test.edu
with a date more current than 2012-03-16.
select *
from nodes n
join nodes nlater
on n.name = nlater.name
and n.reportedat < nlater.reportedat
This question already has an answer here:
MySQL - Thousands separator
(1 answer)
Closed 9 months ago.
I have a query:
select sum(invoiceamount) as invoice
from fact_salescount
where year in ({YEAR})
and month >= ({FROMMONTH})
and month <= ({TOMONTH})
This query can return a value from 100.00 to 15034115.93. It will return ONE value.
I would like to add, for each 000, like this: 15,034,115.93
I've seen a lot of similar questions, but none match mine. I hope someone can help me out.
I am using Pentaho and MySQL, and creating these queries within the Design Studio.
SELECT FORMAT(sum(invoiceamount),2)
FROM fact_salescount
WHERE year IN ({YEAR})
AND month >= ({FROMMONTH})
AND month <= ({TOMONTH})
This should do what you want, but I still don't like formatting number in the backend.