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

NetTuts.com:
Programming With Yii2: Timestamp Behavior
May 22, 2015 @ 14:47:33

NetTuts.com has posted the next part of their "Programming with Yii2" tutorial series today. This new tutorial in the series focuses on the use of the timestamp behavior to assign the current date to an object (like for create or update dates).

In this tutorial, we'll explore Timestamp Behaviors, which reduce the amount of code you need to write with each new model for the common operation of creating timestamps for inserts and updates. We'll also dive into the Yii2 source code, examining how a behavior is implemented.

He starts with a brief look at what behaviors are (a reminder for those that may have already read about the sluggable and blameable behaviors). He then gets into the Timestamp behavior specifically and how to apply it to the sample project's "Status" instances. He shows the updates needed for the behavior configuration and rules. He also looks inside the component at the code that makes it up and the "touch" method it provides.

tagged: tutorial timestamp behavior yii2 framework series touch

Link: http://code.tutsplus.com/tutorials/programming-with-yii2-timestamp-behavior--cms-23329

PHPMaster.com:
Working with Dates and Times in PHP and MySQL
Mar 01, 2012 @ 14: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.

tagged: date time mysql datetime tutorial format unix timestamp

Link:

Brian Swan's Blog:
Sorting Azure Table Entities by Timestamp with PHP
Apr 27, 2011 @ 15: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.

tagged: azure sort table timestamp arraymultisort tutorial

Link:

Pumka.net:
Why MySQL timestamp is 24 seconds different from PHP
Oct 26, 2010 @ 16: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.

tagged: mysql timestamp second leapsecond

Link:

Zend Developer Zone:
Zend_Log timestamp filter
Jul 19, 2010 @ 17: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.

tagged: zendframework zendlog custom filter timestamp

Link:

ZendCasts.com:
Logging with Timestamps and Doctrine Event Listeners
Feb 18, 2010 @ 14: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.

tagged: timestamp logging doctrine database integration

Link:

DevShed:
Logging in PHP Applications
Dec 08, 2008 @ 19: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).

tagged: log tutorial pear trace audit history priority timestamp location

Link:

ThinkPHP Blog:
Put out the age of a date in words
Apr 11, 2008 @ 15: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).

tagged: date format timestamp week month day output

Link:

Developer Tutorials Blog:
Calculating date difference more precisely in PHP
Mar 11, 2008 @ 13: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.

tagged: date calculate precise difference timestamp function

Link:

Photogapple.co.uk:
time_since
Apr 20, 2007 @ 16: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.

tagged: timesince date timestamp compare difference format output timesince date timestamp compare difference format output

Link:


Trending Topics: