![]() |
|
![]() |
Curriculum Vitae / Introduction / Tutorials and other resources for web and E-Commerce programming! |
|
If you think of working with me, contact me by an email now, and you need to fill up your project needs here. |
Certified expert level of workmanship :-)My approved qualifications for internet applications, and your business: You will need to login as a service buyer. You will find more reasons to satisfy if you work with me. Save your budget. Find an expert level solution. Instant ContactProven expertises in: MySQL Stored Procedures, Regular Expressions, Smarty Template Engine, CURL, Data processing n Sanitization, Debugging (are your projects abandoned?), and high quality programming in shorter time period. Please ask for a detailed information if you needed it. Need a support? Ask me now. Let us discuss it. Professional Community PresenceWatch my forum updates in Smarty. I frequently share my skills at the Smarty Forum. Send your business requirementsPlease post your needs here, and our team will contact you at our earliest. | Home » CV | My Tutorials | My Articles | Glossary | My Photos | Contact Me
Power of PHP | Database Connection | Database Class | HTML Spam Filter | Domain Name | Database based *CONFIG* variables | Synchronizing Databases | Mistakes with website dates | Random Users | URL GET Class | MySQL Class | DB to HTML Form | Link Roller Written By: I am happy to receive your PHP codes and put it into this site, under your own name. You can send them in my email. I just want to make this site rich with quality PHP tutorials. Mistakes with website dates and times Theme: Read date/time from webserver and Database server by PHP, and connection to MySQL server from PHP. Have you ever notices that websites today are most frequently designed for the PHP? You can normally guess it, because you can see ".php" in the last of the URL of the website, as in http://www.ymlp.com/index.php, for example. Older versions may use .php3 or .php4 or similar. If you too own a webserver, you can put any extension to the file and treat as the PHP script. But this is not a major issue here. Now, let us start a simple trick for the PHP application writes regarding the date values. This is a special case, if you deal with the database through PHP in the webserver. There may be two dedicated computers for the web server and the database server. And by connecting to any one, you can get the date or time values. PHP alone can read the system time and date from the webserver. There are different format specifiers to read the different characteristics of date or time. While reading the date or time, you get something that is not exactly useful for you. You have to format it into the form you may require to present in your website. Here are the most commonly required format specifiers and their meanings. Later, you will learn how to use them. [PHP Table] In PHP this is the normal style of reading the date or time. <?php echo('Today is: '.$date.' '.$time); There are most likey errors you may commit while writing PHP scripts. Note that you have to read the time with the date() function and not the time(). You must exactly pass the format specifiers to the date() as parameters, so that the result comes as you expect. You must have a strong and confident use of format spefiers. Say, forgetting SHIFT key writing the format spefifier for the 4 digits year (eg. 2005) gives you 2 digits year (05), and you might surprise! So, be careful while using those characters. In the above example, '-', or '/' or ':', SPACE do not bear any significant meaning to read the date. We normally try use the YYYY-MM-DD and HH:MM:SS formats for the date and time respectively. Date values are separated with a '-' or '/' and so, date sometimes may look like YYYY/MM/DD. The term MM is repeated twice for month and minute. That is not possbile while programming. (Check the above table clearly.) And even note, the format specifiers are not common ones. To read minute, you may use 'm' but you MUST use 'i', because 'm' reads month with leading zero, eg, 01 for Janaury. These types of conventions may require you to refer to the table for format specifiers while reading the date. Even problems arise while reading dates from the MySQL server too. The format specifiying characters are almost the same. But, you must use a '%' character before the format specifier. Below is an example to read a 4 digits year value from the MySQL. mysql> SELECT DATE_FORMAT( NOW(), '%Y' ); +----------------------------+ | DATE_FORMAT( NOW(), '%Y' ) | +----------------------------+ | 2005 | +----------------------------+ 1 row in set (0.00 sec) The character, 'Y' needs to be CAPITALISED. And it is not CAPITALISED because all other MySQL strings are in capital letters in the above example. '%Y' reads a YYYY format date, ie. 4 digits. The NOW() reads the current date/time in the format: YYYY-MM-DD HH:MM:SS. While, it was only 'Y' for the PHP to do the same thing. Below is a table for MySQL format specifiers for the date. [ MySQL Table ] 11:44 PM 2/23/05 www.php.net\MANUAL\EN\function.date.php.htm |
| website and the contents unless speficied are owned by - Bimal Poudel.
All rights reserved. This website contains personal materials. Contact Me. Last modification: 2007-03-01 06:02:41 |