MySQL date formatting in Dreamweaver MX Page 1 sur 2 Grafik Kaos

Aug 17, 2002 - MySQL date formatting in Dreamweaver MX. This tutorial shows how to format a MySQL date field so that it can be displayed in a proper format.
54KB taille 4 téléchargements 173 vues
Grafik Kaos - MySQL date formatting in Dreamweaver MX

Page 1 sur 2

August 17, 2002

Number of Active Users:

Search:

MySQL date formatting in Dreamweaver MX This tutorial shows how to format a MySQL date field so that it can be displayed in a proper format. e.g 20020711000000 -> 11th July 2002 00:00:00. This has been quite a common question asked over the internet. Hopefully, this tutorial should shed some light on how to overcome the problem. I am writing this tutorial with the assumption that you know how to create a connection with MySQL, how to create recordsets and how to display them in Dreamweaver MX. 1. Start off by creating the recordset that you need. If you are on the Simple dialog, clik on the Advanced to go to the bigger and more in depth window. Add your SQL command exactly in the way it is shown below, but use your table name and field name. For example, if you have a table called Users and the fields contained in it are: Name, Email, Website and LogOnDate, your SQL should look like:

SELECT Users.Name, Users.Email.... so on and so forth....... Once you have done that, have a look at the image below and pay particular attention to the text that has been underlined in red.

2. The underlined text shows how the date is formatted. The DATE_FORMAT(date, format) function in MySQL sets way we want our date to look. So in the case of the Users table mentioned earlier, the SQL for the date field should be DATE_FORMAT(Users.LogOnDate, '%d/%m,%Y' %T') as logged_date. What happens here is that, DATE_FORMAT takes the value of LogOnDate, changes the format of it and stores it in logged_date. This new field is also added to your recordset in the Bindings Panel. The date will be changed from the long string of numbers we normally get to the dd/mm/yyyy format. %d will show the day as two numbers but without the 'th', %m will show the month as two numbers (e.g. 01, 05......) while % Y will display the year in full (YYYY). %T will show the time in a 24 hour format. If you do not have the TimeStamp or DateTime set as your default value in date field, %T will not be required. (Have a look here for date format styles) 3. Finally, in order to display our newly formatted date on your php page, type . Your new date should end up from looking like 20020711135512 to 11/07/2002 13:55:12 I hope this tutorial helps any of you web developers overcome the date problem in MySQL.

http://members.lycos.co.uk/grafikkaos/tutorials/web_design/date_formats.php

17/08/2002

Grafik Kaos - MySQL date formatting in Dreamweaver MX

Page 2 sur 2

Join Mailing List E-mail:

Submit

Home | Portfolio | Tutorials | Links | Models | Services | Contact | Extensions | Applications © Grafik Kaos 2000 - 2002 All Rights Reserved

http://members.lycos.co.uk/grafikkaos/tutorials/web_design/date_formats.php

17/08/2002