 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
PHPMaster.com: Working with Dates and Times in PHP and MySQL
by Chris Cornutt March 01, 2012 @ 08:51:47
On PHPMaster.com today there's a new tutorial by Sean Hudgston about working with dates and times via the PHP date functions and how they cooperate with dates/times from a MySQL database.
When working in any programming language, dealing with dates and time is often a trivial and simple task. That is, until time zones have to be supported. Fortunately, PHP has one of the most potent set of date/time tools that help you deal with all sorts of time-related issues: Unix timestamps, formatting dates for human consumption, displaying times with time zones, the difference between now and the second Tuesday of next month, etc. In this article I'll introduce you to the basics of PHP's time functions (time(), mktime(), and date()) and their object-oriented counterparts, and then take a look at MySQL dates and show you how to make them play nicely with PHP.
His examples include how to get the current Unix time, formatting dates/times, making timestamps and working with the more powerful DateTime objects. On the MySQL front, he shows the result of a normal date select, one using the "unix_timestamp" function and how to shift the result based on the user's timezone.
voice your opinion now!
date time mysql datetime tutorial format unix timestamp
Brian Swan's Blog: Sorting Azure Table Entities by Timestamp with PHP
by Chris Cornutt April 27, 2011 @ 10:48:17
Brian Swan has a quick new post to his blog for the PHP + Azure users out there on how to easily sort table entities by a timestamp through the Azure SDK for PHP. The timestamp is a property on the parent storage table class, so you don't need to create it in your entity, it's already there.
The problem boils down to sorting an array of objects by a timestamp property, so the information here is nothing that hasn't been done before. However, after spending some time looking for a way to use a filter in the Windows Azure SDK for PHP API, I didn't find one, so I'm hoping this post might save others some time. In the end, my solution simply uses the PHP array_multisort function.
Sample code is included - a basic class extending Microsoft_WindowsAzure_Storage_TableEntity, a fetch for the entity set of the contacts and using a custom "objSort" method that sorts based on the returned timestamp values from the object set.
voice your opinion now!
azure sort table timestamp arraymultisort tutorial
Pumka.net: Why MySQL timestamp is 24 seconds different from PHP
by Chris Cornutt October 26, 2010 @ 11:24:31
On the Pumka.net blog, Anton Oliink has an interesting problem where his timestamp on the PHP side of his application was different than the one on his MySQL backend's side - by 24 seconds, in fact.
You may find that timestamp value returned by MySQL UNIX_TIMESTAMP() function is 24 seconds grater than those returned by PHP functions and classes like strtotime(), mktime, DateTime::getTimestamp(), Zend_Date::getTimestamp().
As it turns out, the issue isn't' really an "issue" after all - it's caused by MySQL's compensation for leap seconds. He gives a few ways you can avoid it being an issue in your application, though: disable leap seconds, only convert to timestamps on the PHP side or just use the "unix_timestamp()" and "from_unixtime()" methods to work with the values.
voice your opinion now!
mysql timestamp second leapsecond
Zend Developer Zone: Zend_Log timestamp filter
by Chris Cornutt July 19, 2010 @ 12:24:48
On the Zend Developer Zone there's a recent post about a custom filter that's been developed to help filter events based on time instead of just logging them as a whole.
For one of my recent project, which is using Zend_Log component of the Zend Framework, I had a demand in which I needed to be able to filter log events based on the time they occurred. As out of the box, Zend_Log component does not have such filter, I decided to create one that will fulfill my demands.
The log filter, NP_Log_Filter_Timestamp, it allows you to set rules for things like hour, minute year, day of the week, etc. and can be used anywhere you'd create a normal Zend_Log instance. Pass it in the format you'd like to use (that idate can use), a value to evaluate and a comparison operator. Two code snippets show how it's used.
voice your opinion now!
zendframework zendlog custom filter timestamp
DevShed: Logging in PHP Applications
by Chris Cornutt December 08, 2008 @ 13:52:10
DevShed has posted a new tutorial today looking at one of the more useful tools a developer can add into an application - logging.
If there is no logging mechanism, then if there's a goof-up in a production environment, you have absolutely no idea what went wrong. The only thing which a support developer can do in this case is to reproduce the issue at the developer end, which sometimes work and sometimes don't.
The look at the types of logging (trace logs, audit logs and user logging/history) and create a simple class that allows flexibility for file location, priority and timstamping. Their script contains a writelog method that does all the work (including pushing it through the PEAR logging class).
voice your opinion now!
log tutorial pear trace audit history priority timestamp location
ThinkPHP Blog: Put out the age of a date in words
by Chris Cornutt April 11, 2008 @ 10:37:53
On the ThinkPHP blog today, Annika Rabea shares a method for outputting dates in words rather than in the usual numbers most applications use.
Recently, I have to output the age of a date in words and didn't have a framework to work with. The first steps were to parse the given date into an array and create a timestamp with the individual parts. The difference between the timestamp of now and the created timestamp yielded the age in seconds. The result can be used to compare with seconds of a day, week, etc.
The code snippet in the post outputs the difference between two timestamps (then and now) it a bit more friendly way (ex. 4 months, 2 weeks, 2 days).
voice your opinion now!
date format timestamp week month day output
JSLabs Blog: How to stop IE from caching AJAX requests
by Chris Cornutt February 05, 2007 @ 08:05:00
If you've ever had the frustration of working with Ajax in Internet Explorer and have noticed it caching the requests/results, you might want to check out this new post on the JSLabs blog for a helpful hint.
While working on an AJAX project over the weekend, I ran into the following issue: (through a GET request), every time I tried to call a certain function, It was returning the same data (which was supposed to be different each time)
First, he tried just changing the headers (via PHP's header function) to see if IE would understand the new message, but to no avail. He finally figured out that, despite whatever headers were sent or how much the content changed, what he really needed to do was to provide the script some kind of unique identifier with each request (just appended to the url) so that IE knew the request was different. His weapon of choice was a date/time value.
voice your opinion now!
ajax internetexplorer cache request timestamp unique header ajax internetexplorer cache request timestamp unique header
|
Community Events
Don't see your event here? Let us know!
|