This is a list of handy tips that could help you in a blink on how to convert String to Date in SQL. This post cover 5 popular databases (Oracle, MySQL, DB2, PostgreSQL, Informix)
Post your comment here if you find this post useful or want to contribute more explaination.
Oracle
Syntax:
to_date(date_string, format)
Example:
SELECT user.name, user.location FROM user
WHERE user.starteddtm = to_date('20/10/2007 16:01', 'dd/mm/yyyy hh24:mi');
Read more…
If you are using Ubuntu version 7.10 or above, you can install PHPMyAdmin using apt-get.
I assume that you have apache and php installed on your system.
The following steps is guiding you to install PHPMyAdmin and get it running
- Run this command
sudo apt-get install phpmyadmin
- Edit this file
sudo vi /etc/apache2/apache2.conf
- Add this line
Include /etc/phpmyadmin/apache.conf
- Save file and exit
- Now go to http://localhost/phpmyadmin
- Login using your mysql root account and make sure all the databases/tables are showing
One day you forgot your root password for your MySQL database server and blaming yourself for not written it somewhere for easy access.
Ok, do it no more! here’s my short version (of official instruction) for advance user who does not need too much of instruction details
On Windows
- As admin, Stop the MySQL server, make sure it’s completely stop
- Create a text file eg.
C:mysql-init.txt and past the following statement in
UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE User='root';
FLUSH PRIVILEGES;
- Open up your Windows Command Prompt
- Run this command
C:mysqlbinmysqld-nt --init-file=C:mysql-init.txt
Change path if your sever install on somewhere else.
For wizard installation of mysql, you might have to do this
"C:Program FilesMySQLMySQL Server 5.0binmysqld-nt.exe"
--defaults-file="C:Program FilesMySQLMySQL Server 5.0my.ini"
--init-file=C:mysql-init.tx
- Now delete
C:mysql-init.txt then restart MySQL server again
On Linux or Unix
- Stop MySQL server as follow
Find .pid file in /var/lib/mysql/, /var/run/mysqld/ and /usr/local/mysql/data/
- Now run
$ kill `cat /mysql-data-directory/host_name.pid`
- Create a text file eg.
/home/yourid/mysql-init and past the following statement in
UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE User='root';
FLUSH PRIVILEGES;
- Start mysql server with the following options
mysqld_safe --init-file=/home/me/mysql-init &
- Delete mysql-init file then finished
Alternative but less secure
- Stop
mysqld and restart it with the --skip-grant-tables option.
- Connect to the mysqld server with this command
- Now run the following statement
UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE User='root';
FLUSH PRIVILEGES;
- Finished