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

Brian Moon's Blog:
Errors when adding/subtracing dates using seconds
Jan 17, 2012 @ 17:19:22

Brian Moon has a reminder about date handling in PHP - days are not always 86400 seconds long, sometimes there's "leap seconds" included too. Thankfully, there's easy ways around it:

The problem with this is that it assume that there are only 86400 seconds in every day. There are in fact not. On days when the clocks change for daylight savings time, there are either 1 hour more than that or 1 hour less than that. In addition, there are also leap seconds put into our time system to keep us in line with the sun. There is one this year, 2012, on June 30th in fact. Since they don't happen with the regularity that daylight savings time does, it may be easy to forget those. Luckily, for this problem, the solution is the same.

His first solution involves letting strtotime do the work for him, internally calculating the leap seconds or any other issue that might come up. As an alternate solution, he also mentions "doing your math at noon" - this gives you enough leeway to make the offset leap seconds could cause a much smaller risk.

tagged: error add subtract date seconds strtotime noon

Link:

James Cohen's Blog:
Working with Date and Time in PHP
May 04, 2011 @ 13:59:23

James Cohen has a new post to his blog today looking at some of the built-in functionality that PHP has to work with dates and times including simple things like strtotime and the DateTime feature.

A lot of people ask questions relating to date and time in PHP. Here are some answers to the most commonly asked questions and common mistakes.

He covers the differences between working with dates in strtotime, worrying about timezone settings and compares the strtotime/DateTime methods for formatting and returning dates, modifying dates, converting between timezones as well as finding the difference between two timezones.

tagged: date time datetime strtotime timezone tutorial procedural oop

Link:

Enavu.com:
PHP Smart Date Parsing: Natural Language Input (task.fm explained)
May 03, 2010 @ 15:06:24

On the Enavu.com blog today there's a new tutorial talking about smart date parsing using just the normal natural language you use every day.

Have you ever tried task.fm ? task.fm uses something called “Natural Language Input,” and it’s very interesting. To put it simply, you enter a natural language input such as, “Pick up my kids from school tomorrow 3pm” or “Pool party this Saturday at 4pm.”

They suggest using the strtotime function to handle some of the difficult work. There's a snippet of code included showing it in use and an explanation of how the function would handle the parts of the sentence "I am going to go to the beach at 3pm tomorrow".

tagged: taskfm tutorial strtotime parse date

Link:

Daniel Cousineau's Blog:
Calculating Daylight Savings Time Boundary In PHP
Mar 11, 2009 @ 17:02:15

Daniel Cousineau has written up some timely advice in a new post to his blog. It looks at pinpointing the time boundary for Daylight Savings Time in a PHP script (when it starts and when it ends).

I had an issue recently where I needed to calculate the Unix timestamp for the daylight savings time boundaries. According to the United States Naval Observatory, daylight savings time begins the Second Sunday of March and ends on the First Sunday of November.

He looks at using the strtotime function to calculate these dates but points out some quirks - like what happens when you just give it a month or something like "second Sunday". His solution was to go back one day ("March 0" instead of "March 1") and calculating the time from there, including that first full day of March in the calculation.

tagged: calculate daylight savings time boundary march november strtotime

Link:

Derick Rethans' Blog:
Calculating start and end dates of a week
Nov 16, 2006 @ 21:13:37

Derick Rethans has posted a quick tip to his blog today:

A friend asked "How do I calculate start (monday) and end (sunday) dates from a given week number for a specified year?" Instead of having to come up with your own algorithm you can simply do the following in PHP 5.1 and higher.

The (technically) three-line code uses ISO format for the date to tell you which day is the starting day of that week and which is the end. He only explains this format just a bit, so if you want more information, check out the strtotime function page.

tagged: start day end week date strtotime iso format start day end week date strtotime iso format

Link:

Derick Rethans' Blog:
Calculating start and end dates of a week
Nov 16, 2006 @ 21:13:37

Derick Rethans has posted a quick tip to his blog today:

A friend asked "How do I calculate start (monday) and end (sunday) dates from a given week number for a specified year?" Instead of having to come up with your own algorithm you can simply do the following in PHP 5.1 and higher.

The (technically) three-line code uses ISO format for the date to tell you which day is the starting day of that week and which is the end. He only explains this format just a bit, so if you want more information, check out the strtotime function page.

tagged: start day end week date strtotime iso format start day end week date strtotime iso format

Link:

Derick Rethans' Blog:
Calculating start and end dates of a week
Sep 06, 2006 @ 12:03:24

With just a quick handy code snippet posted on his blog today, Derick Rethans shares these two lines to help grab the start and end dates of a week in question.

A friend asked "How do I calculate start (monday) and end (sunday) dates from a given week number for a specified year?" Instead of having to come up with your own algorithm you can simply do the following in PHP 5.1 and higher.

The code makes use of the ISO8601 datetime functionality to grab the correct value from a strtotime command. Derick also briefly explains how it all works.

tagged: start date end week strtotime iso8601 datetime format start date end week strtotime iso8601 datetime format

Link:

Derick Rethans' Blog:
Calculating start and end dates of a week
Sep 06, 2006 @ 12:03:24

With just a quick handy code snippet posted on his blog today, Derick Rethans shares these two lines to help grab the start and end dates of a week in question.

A friend asked "How do I calculate start (monday) and end (sunday) dates from a given week number for a specified year?" Instead of having to come up with your own algorithm you can simply do the following in PHP 5.1 and higher.

The code makes use of the ISO8601 datetime functionality to grab the correct value from a strtotime command. Derick also briefly explains how it all works.

tagged: start date end week strtotime iso8601 datetime format start date end week strtotime iso8601 datetime format

Link:

Dallas PHP Users Group:
PHP4 to PHP5 Minor gotcha
Jan 12, 2006 @ 12:58:21

On the Dallas PHP Users Group website today, there's quick little "gotcha" by MonkeyT when it comes to using the strtotime() function.

strtotime translates a date presented in various formats into a unix timestamp. It allows the syntax "+2 weeks" and various other time units to push that chosen date translation into the future. In 4.3.10, php would allow a space between the + and the beginning of the parameter. that doesn't seem to be the case any more. ("+3 days", not "+ 3 days"). Other than that, pretty smooth changeover so far.

It's pretty subtle, but I could potentially cause some headaches in the future - so keep an eye out!

tagged: php4 php5 upgrade strtotime space after plus php4 php5 upgrade strtotime space after plus

Link:

Dallas PHP Users Group:
PHP4 to PHP5 Minor gotcha
Jan 12, 2006 @ 12:58:21

On the Dallas PHP Users Group website today, there's quick little "gotcha" by MonkeyT when it comes to using the strtotime() function.

strtotime translates a date presented in various formats into a unix timestamp. It allows the syntax "+2 weeks" and various other time units to push that chosen date translation into the future. In 4.3.10, php would allow a space between the + and the beginning of the parameter. that doesn't seem to be the case any more. ("+3 days", not "+ 3 days"). Other than that, pretty smooth changeover so far.

It's pretty subtle, but I could potentially cause some headaches in the future - so keep an eye out!

tagged: php4 php5 upgrade strtotime space after plus php4 php5 upgrade strtotime space after plus

Link:


Trending Topics: