Select all columns but unix_timestamp createdate [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Using PHP/MySQL
I need to select all the columns in the table, but convert the column 'createdate', which is saved as a current_timestamp to a unix_timestamp within the query.

You can use MySQL's UNIX_TIMESTAMP() function:
SELECT *, UNIX_TIMESTAMP(createdate) AS unix_createdate FROM my_table

This can be achieved with the UNIX_TIMESTAMP() function built in MySQL.
mysql> SELECT UNIX_TIMESTAMP();
-> 1196440210
mysql> SELECT UNIX_TIMESTAMP('2007-11-30 10:30:19');
-> 1196440219
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_unix-timestamp

Related

How to insert a date in mysql via php? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
i have date in a variable as
$d = 2014-MAR-20;
How to insert this $d value to a field having type 'Date' in mysql using php?.
$d=date('Y-m-d',strtotime($d));
Then insert it to your table with your date column.
mysqli_query($YourConnection,"INSERT INTO yourTable (date) VALUES ('$d')");
If you are using PDO
$d = "2014-MAR-20";
$date =date('Y-m-d',strtotime($d)); // convert to Mysql format
Insert date value using PDO prepared statement
$stmt = $db->prepare("INSERT INTO table(`date`) VALUES(?)");
$stmt->execute(array($date));

How to do less than, more than with wpdb (wordpress database)? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
How do I do the less than AND greater than $date in wpdb?
$date = ('Y-m-d');
$wpdb->get_results($wpdb->prepare('SELECT * FROM product_history WHERE enddate = "%d";', array($date)));
I wan't to get history where enddate is today or in present time, BUT also more than 0000-00-00.
Try this one
$wpdb->get_results($wpdb->prepare('SELECT * FROM product_history WHERE enddate >= CURDATE()'));
It will work definitely.
Incase of Date with Time, you have to select field DATETIME in MySQL and in that case you should run query something like
$wpdb->get_results($wpdb->prepare('SELECT * FROM product_history WHERE enddate >= NOW()'));
Using this query, You can filter data from current time.

Sorting month name in mysql [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I stored the month name in database as string which looks like
Apr-2013
May-2013
...
How could i sort the table month wise ?
Any help is appreciated.
You will have to format the date in order to sort it:
select aDate from t
order by str_to_date(aDate,'%b-%Y')
This is very inefficient, though. I'd recommend you to update that field and make it a date field or at least two ints: one for the month and one for the year. Then, if you need to get the name of the month you could use the monthname(date) function.
SELECT
*
FROM
dates
ORDER BY
STR_TO_DATE(date, '%b-%Y')
SQL Fiddle

MySQL query to display one record before today's date [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I can't find an answer to my question, it's probably easy but... anyway!
I have a database with every NHL game for one specific team in a table. Every game has been entered in the good order.
On my home page, I would like to display the upcoming game as well as the result of the previous game. How can I create a mySQL query to display the previous game based on today's date?
Thanks!
Do your game records have a timestamp or datetime value?
If so you could write a query ordering your games by the date smaller that now() and limit by one.
The query should look like this:
select * from games where gamedate < now() order by gamedate desc limit 1

How can i fetch and compare time of related post from database? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am using mysql as database and saved time as time stamp of related posts in table, now i want to fetch the post made rrecently . How can i compare and fetch the post made recently?
you can fetch rows in descending order of your column (time_stamp).
ex:
SELECT * FROM Table_Name ORDER BY col_time_stamp DESC;
col_time_stamp : is the column
select top 1 * from posts order by timestamp desc
try this
SELECT * FROM Table_Name ORDER BY col_time_stamp DESC LIMIT 0;

Categories