All In One Script
MENU

Convert from MySQL datetime to another format with PHP

by 5:06:00 AM
undefined
Convert from MySQL datetime to another format with PHP I have a datetime column in MySQL. How can I convert it to the display as mm/dd/yy H:M (AM/PM) using PHP? Solution : To convert a date retrieved from MySQL into the format requested (mm/dd/yy H:M (AM/PM)): // $datetime is something like: 2014-01-31 13:05:59 $time = strtotime($datetimeFromMysql); $myFormatForView = date("m/d/y g:i A", $time); // $myFormatForView is something like: 01/31/14 1:05 PM Refer to the PHP date formatting options to adjust the format. http://stackoverflow.com/questions/136782/convert-from-mysql-datetime-to-another-format-with-php/5367048#5367048

How to add 30 minutes to a JavaScript Date object?

by 5:03:00 AM
undefined
How to add 30 minutes to a JavaScript Date object? I'd like to get a Date object which is 30 minutes later than another Date object. How do I do it with JavaScript? Solution : If you are doing a lot of date work, you may want to look into JavaScript date libraries like Datejs or Moment.js This is like chaos's answer, but in one line: var newDateObj = new Date(oldDateObj.getTime() + diff*60000); Where diff is the difference in minutes you want from oldDateObj's time. It can even be negative.

MySQL Query GROUP BY day / month / year

by 5:00:00 AM
undefined
MySQL Query GROUP BY day / month / year Is it possible I make a simple query to count how many records I have in a determined period of time like a Year, month or day, having a TIMESTAMP field, like: SELECT COUNT(id) FROM stats WHERE record_date.YEAR = 2009 GROUP BY record_date.YEAR Or even: SELECT COUNT(id) FROM stats GROUP BY record_date.YEAR, record_date.MONTH To have a monthly statistic. Thanks! Answer: GROUP BY YEAR(record_date), MONTH(record_date) Check out the date and time functions in MySQL. http://stackoverflow.com/questions/508791/mysql-query-group-by-day-month-year/508806#508806

How to get a list of MySQL User Accounts

by 4:37:00 AM
undefined
How to get a list of MySQL User Accounts I'm using the MySQL command line utility and can navigate through a database. Now I need to see a list of user accounts. How can I do this? I'm using MySQL version 5.4.1. Answer :  Use this query: SELECT User FROM mysql.user; Which will output a table like this: +-------+ | User | +-------+ | root | +-------+ | user2 | +-------+ As Matthew Scharley points out in the comments on this answer, you can group

How do you list all triggers in a MySQL Database?

by 4:34:00 AM
undefined
How do you list all triggers in a MySQL Database? What is the command to list all triggers in a MySQL database? Answer :  The command is: show triggers or you can access the INFORMATION_SCHEMA table directly by: select trigger_schema, trigger_name, action_statement from information_schema.triggers You can do this from version 5.0.10 onwards. More information about the TRIGGERS table is here. Source

MySQL Error 1093 - Can't specify target table for update in FROM clause

by 4:32:00 AM
undefined
MySQL Error 1093 - Can't specify target table for update in FROM clause I have a table story_category in my database with corrupt entries. The next query returns the corrupt entries: SELECT * FROM story_category WHERE category_id NOT IN ( SELECT DISTINCT category.id FROM category INNER JOIN story_category ON category_id=category.id); I tried to delete them executing: DELETE FROM story_category WHERE category_id NOT IN ( SELECT DISTINCT category.id FROM category INNER JOIN story_category ON category_id=category.id); But I get the next error:          

How do I quickly rename a MySQL database (change schema name)?

by 4:28:00 AM
undefined
How do I quickly rename a MySQL database (change schema name)? The MySQL manual at MySQL covers this. Usually I just dump the database and reimport it with a new name. This is not an option for very big databases. Apparently RENAME {DATABASE | SCHEMA} db_name TO new_db_name; does bad things, exist only in a handful of versions, and is a bad idea overall. This needs to work with InnoDB, which stores things very differently than MyISAM. Answer : For InnoDB, the following seems to work: create the new

Instagram