MySQL Timestamp how to write a query to select weekdays only - mysql

I want to write mysql for filter weekday result only. I used timestamp for store dates. can anyone help me to this?
eg; SELECT * FROM mytable WHERE WEEKDAY('mydate_field')

Considering you mean excluding Sunday and Saturday.
SELECT * FROM mytable
WHERE DAYOFWEEK('mydate_field') in (2,3,4,5,6)

Try something like this:
SELECT * FROM mytable
WHERE WEEKDAY('mydate_field')<5

you can also try like this.
SELECT * FROM your_table WHERE WEEKDAY(mydate_field)>0 AND WEEKDAY(mydate_field)<6;

Related

How do I run my query and add the convert_tz(FROM (FROM_UNIXTIME

This will be simple for you. I have a query that returns all the information in the table but the dates are all Unix timestamp and I need to convert that one column.
These are my 2 strings and I just need to know how to link them together:
Query 1:
SELECT * FROM `wrd_project_payment_transactions`
The conversion:
SELECT CONVERT_TZ(FROM_UNIXTIME(`datemade`), ##session.time_zone, '+00:00')
FROM `wrd_project_payment_transactions`
I'm a noob so be gentle.
Thanks!
SELECT *, CONVERT_TZ(FROM_UNIXTIME(`datemade`), ##session.time_zone, '+00:00') AS convertedTime
FROM `wrd_project_payment_transactions`

How to select rows within some date range

I want to select rows that falls between some date range, I tried the following query but it didn't work.
SELECT * FROM tbl WHERE DATE_FORMAT(date_col, '%2011-%c-%e') BETWEEN '2011-11-28' AND '2011-12-5'
It doesn't seem like the BETWEEN keyword works on date. Please how do I get the results? Thanks
You don't need to use DATE_FORMAT if you want to compare dates.
SELECT *
FROM tbl
WHERE DATE(date_col) BETWEEN '2011-11-28' AND '2011-12-05'
Your code compares strings, assuming you use DATE_FORMAT(date_col, '%Y-%c-%e')
SELECT * FROM tbl WHERE DATE_FORMAT(date_col, '%Y-%m-%d') BETWEEN '2011-11-28' AND '2011-12-5'

query data in mysql using a date in a datetime column

I want to query data in mysql. The problem is the column is datetime(dpost) and i will use a date in the where clause.
SELECT * FROM `uid1000_qposts` WHERE `dpost`="2011-12-06"
this query doesn't return any results. Is there any possible way I can query data using date against a datetime column?
thanks
SELECT * FROM `uid1000_qposts` WHERE date(`dpost`) = '2011-12-06'
Try this:
SELECT * FROM `uid1000_qposts` WHERE DATE_FORMAT(dpost,'%Y-%m-%d')='2011-12-06'
WHERE dpost between "2011-12-06 00:00:00" and "2011-12-06 23:59:59"
Another possibilities is using
DATE_FORMAT(dpost,'%Y-%m-%d')="2011-12-06"
but is not recommended,
as it won't make use on any index (even there is)
SELECT * FROM `uid1000_qposts` WHERE date(`dpost`) = '2011-12-06'

Retrieve records based on Date

I have a date column in my table.
Is there any way in mysql to retrieve record based on date excluding the time part?
I have tried appending * but does not seems to work.
SELECT * FROM myTable where filterDate="2010-08-01 *"
Is there any way to do it like this rather then filtering it by using between?
Thanks.
SELECT * FROM myTable where filterDate LIKE "%2010-08-01 %"
You can use DATE_FORMAT function of mysql
SELECT * FROM myTable where DATE_FORMAT(filterDate,'%Y-%m-%d') ="2010-08-01"
Try this
SELECT DATE_FORMAT(filterDate , '%d-%m-%Y') AS new_date FROM table_name WHERE
DATE_FORMAT(filterDate , '%d-%m-%Y') = '2010-08-01'

mySQL: select * in combination with UNIX_TIMESTAMP

Right now I'm retrieving data from my database as follows:
SELECT id, UNIX_TIMESTAMP(cdate) as myunixdate, permalink, title FROM mytable
But I would like to do it as follows, but it doesn't work.
SELECT *, UNIX_TIMESTAMP(cdate) FROM mytable
My question is, how can I combine UNIX_TIMESTAMP without having to specify all the other fields?
Are you sure you didn't try this?
SELECT UNIX_TIMESTAMP(cdate), * FROM mytable
This won't work as the * has to come first:
SELECT *, UNIX_TIMESTAMP(cdate) FROM mytable
Aliasing it will make it easier to reference in your code:
SELECT *, UNIX_TIMESTAMP(cdate) AS cdate_timestamp FROM mytable
SELECT *, UNIX_TIMESTAMP(cdate) AS my_time_stamp FROM mytable
It works for me in MySQL 6,
Are you sure the second query is the one you really try?
What version of mysql do you use?