 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Davey Shafik's Blog: DateTime Timestamp Parsing
by Chris Cornutt September 20, 2011 @ 11:24:27
In a new post to his blog Davey Shafik looks at parsing dates with DateTime, the new and improved way to handle dates in PHP (well, not so new but definitely improved).
As part of a recent project, I was tasked with taking timestamps returned by an API and displaying fuzzy dates in the final output (e.g. 3hrs ago, in 2 weeks, tomorrow). The timestamp format in question looks like: 2012-09-01T16:20:01-05:00 This format can be found in PHP as the DATE_ATOM or DateTime::ATOM constants, which contain the date() formatter string: Y-m-dTH:i:sP With this in hand, we can now easily parse the timestamp into a useful object.
Parsing the date into a DateTime object is as easy as giving it the date string and telling it how it's formatted. Then you can do all sorts of fun things. He shows how to shift the timezone by name, by time increment - simple (like "1 hour") and more complex (like "1 hour 5 minutes 3 seconds"). You can find out more about the DateTime object in the PHP manual.
voice your opinion now!
datetime parsing manipulation tutorial
Slawek Lukasiewicz's Blog: Working with date and time in object oriented way
by Chris Cornutt June 10, 2011 @ 08:13:14
Slawek Lukasiewicz has a new post today about working with dates and times in PHP on a more object-oriented fashion than in the more traditionally procedural way of just calling PHP date/time functions on the string values.
Date and time manipulation in PHP is mostly connected with functions like: date, time or strtotime. They can be sufficient, but if we want to deal with dates like with objects - we can use DateTime class. DateTime class is not only straightforward wrapper for standard functions, it has a lot of additional features - for example timezones.
He shows how to use the DateTime functionality to return an object you can call several different methods on. He gives examples of the formatting call, comparing one DateTime object to another, how to update the date after the object's created, calculating the difference between two dates and iterating through a certain time period.
voice your opinion now!
time date datetime objectoriented procedural tutorial
XPertDeveloper.com: Is Your PHP Application Affected by the Y2K38?
by Chris Cornutt May 16, 2011 @ 09:22:18
On the XpertDeveloper.com site there's a post reminding you of an date could cause all sorts of problems with your PHP application - the effects of the Y2K38 bug.
Y2K38, or the Unix Millennium Bug, affects PHP and many other languages and systems which use a signed 32-bit integer to signify dates as the number of seconds since 00:00:00 UTC on 1 January 1970. The furthest date which can be stored is 03:14:07 UTC on 19 January 2038. Beyond that, the left-most bit is set and the integer becomes a negative decimal number or a time prior to the epoch.
If you're worried about your application's support for date and time handling, there's a pretty simple fix - replace your current handling with the DateTime functionality. This handles them correctly.
voice your opinion now!
application y2k38 bug datetime integer date
Brian Swan's Blog: SQL Server Driver for PHP Connection Options ReturnDatesAsStrings
by Chris Cornutt February 09, 2011 @ 08:45:28
Brian Swan has a new post to his blog today looking at one of the connection options for the SQL Server driver in PHP - the "ReturnDatesAsStrings" setting that can make handling date and time information simpler for PHP.
This is short post to address a frustration I've seen mentioned on Twitter and in forums a lot: By default, the SQL Server Driver for PHP returns datetime columns as PHP DateTime objects, not strings. This can be especially frustrating if you are not aware of the ReturnDatesAsStrings connection option. By simply setting this option to 1 (or true) when you connect to the server, datetime columns will be returned as strings.
He includes some sample code showing how to use the setting (as a part of the settings array passed in to sqlsrv_connect) and the resulting array key from the fetched results on his sample table. This just gives you one more option for handling dates in your SQL Server-based application, especially if you don't need the full DateTIme object's functionality.
voice your opinion now!
sqlserver driver connection option return date string datetime
DZone.com: Date and time in PHP 5
by Chris Cornutt December 01, 2010 @ 13:58:03
New on the Web Builder Zone today, there's an article about DateTime in PHP5 from Giorgio Sironi introducing you to this very handy built-in feature.
PHP has made some progress here as well, for example with the Standard Php Library and its interfaces. Though, the SPL is incomplete and oriented to performance more than to object-oriented programming: take a look at the SplStack and SplQueue implementation containing 20 different methods to get the idea. However a little gem is shipped with each PHP installation: the datetime extension, which contains the DateTime class and its siblings. Ideally, everything you can do with date_* functions, you can do it with this class.
He includes some code that shows the DateTime object in action as a part of a PHPUnit test case - adding days, subtracting months, date difference and its support of operator overloading. There's also mention of Doctrine's native support for the extension.
voice your opinion now!
datetime date time tutorial introduction
SitePoint PHP Blog: Is Your PHP Application Affected by the Y2K38 Bug?
by Chris Cornutt August 24, 2010 @ 10:12:23
On the SitePoint PHP blog today they pose a question to all PHP developers out there - is your application affected by the Y2K38 bug?
I don't want to be too alarmist, but try running the [given] PHP code on your system. [...] With luck, you'll see "Wednesday 1 February 2040 00:00" displayed in your browser. If you're seeing a date in the late 60's or early 70's, your PHP application may be at risk from the Y2K38 bug!
The bug, caused by a 32-bit operating system, can be helped by running the application on a 64-bit platform (it's due to the limitation of integer size), but there is another option - the DateTime class that handles dates and times differently than the just using the local time settings.
voice your opinion now!
y2k38 bug datetime integer 32bit 64bit
Ibuildings techPortal: Tips for Working with DateTime in PHP
by Chris Cornutt May 04, 2010 @ 13:33:29
In the latest post from the Ibuildings techPortal Lorna Mitchell takes a look at one of the more powerful features included in PHP versions 5.2 and greater - the DateTime class.
In the newer PHP 5.3 versions even more excellent functionality was added. This is a short post to introduce this functionality with a focus on the methods available in PHP 5.2 showing some simple examples of how we can more easily manipulate and display dates without needing to work with timestamps.
She shows how to create a simple DateTime object, how to change up the timezone information related to it and has an example of how to output the format with a call to the format function. She also mentions how they can simplify the storage of date information in a database since they can be moved around between timezones easily (instead of having to calculate the different between where it was created and where it's being used).
voice your opinion now!
datetime tip tutorial example timezone
Squirrel Hacker Blog: PHP DateTime is missing methods in 5.2
by Chris Cornutt April 05, 2010 @ 13:58:26
As SeanJA points out in a new post to his blog, there's two functions that were included in the PHP 5.3 version of the DateTime object in PHp that weren't in the PHP 5.2 version - specifically the get/setTimestamp ones.
These are some strange methods to be missing as a lot of people in the PHP world seem to work on Timestamps using these concepts, so you would have thought that php would have included these methods initially. Unfortunately they did not, so here is a fix for that.
He provides two pieces of code, one to replace the setTimestamp function and the other for the getTimestamp to add in this handy functionality as you might need it.
voice your opinion now!
datetime method missing settimestamp gettimestamp
|
Community Events
Don't see your event here? Let us know!
|