News Feed
Jobs Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

PHPMaster.com:
Working with Dates and Times in PHP and MySQL
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.

0 comments voice your opinion now!
date time mysql datetime tutorial format unix timestamp


Brian Swan's Blog:
Sorting Azure Table Entities by Timestamp with PHP
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.

0 comments voice your opinion now!
azure sort table timestamp arraymultisort tutorial


Pumka.net:
Why MySQL timestamp is 24 seconds different from PHP
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.

1 comment voice your opinion now!
mysql timestamp second leapsecond


Zend Developer Zone:
Zend_Log timestamp filter
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.

0 comments voice your opinion now!
zendframework zendlog custom filter timestamp


ZendCasts.com:
Logging with Timestamps and Doctrine Event Listeners
February 18, 2010 @ 08:16:43

The ZendCasts.com site has recently posted a quick video covering logging and Doctrine event listeners in a Zend Framework application.

This short video is going to be the last in my 2009-2010 series on Doctrine 1.2. I'm wrapping it up with a little example of adding timestamps, logging and using Doctrine's event listener architecture.

The tutorial shows you how to pull in the features of Doctrine to make it easier to create a more complex logging system. He shows how to set up the schema file, add in controller functionality and backend models to make things all work together happily. You can get a copy of the project he's building from his subversion repository.

0 comments voice your opinion now!
timestamp logging doctrine database integration


DevShed:
Logging in PHP Applications
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).

0 comments voice your opinion now!
log tutorial pear trace audit history priority timestamp location


ThinkPHP Blog:
Put out the age of a date in words
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).

0 comments voice your opinion now!
date format timestamp week month day output


Developer Tutorials Blog:
Calculating date difference more precisely in PHP
March 11, 2008 @ 08:40:00

Hasin Hayder has posted his own response to a recent "relative time" article (showing users things like "received 2 days and 3 hours ago") with a more precise method for doing something similar:

This function is production ready and you can use it in any of your application which mainly works with these date difference. I have found it somewhere in web, just forgot the source. Thanks to the unknown author of this excellent function.

The rest of the post is the function itself that takes in the interval string (formatting), the start date, end date and whether to use timestamps or not.

0 comments voice your opinion now!
date calculate precise difference timestamp function


Photogapple.co.uk:
time_since
April 20, 2007 @ 11:07:00

On the Photogapple.co.uk blog today, there's some handy code that can definitely be useful when working with dates in PHP - a function to find the difference between the current time and a timestamp you give it.

I found it incredibly difficult to find any form of time_since function in php so to save anyone else the trouble to hunting through hundreds of useless websites here is the function you may want to use, written by Natalie Downe (you don't want to know how long it took to hunt it down).

The function takes in the value, subtracts the two timestamps and loops through an array of "time chunks" to each other to show nicely formatted output of how long the difference it.

0 comments voice your opinion now!
timesince date timestamp compare difference format output timesince date timestamp compare difference format output


JSLabs Blog:
How to stop IE from caching AJAX requests
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.

1 comment 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!


security component unittest facebook code example release podcast package overview composer opinion install application introduction symfony2 framework hack hhvm language

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework