QA Graphic

Converting Date/Time to Hours

Its easy to display the hours until a certain date using TextExpander. See my example.

Every week I send out Code Freeze reminders to the team. Often when I am sending out emails, it would be handy to know exactly how many hours it is until code freeze. This makes it easy for our remote developers to not have to think about covering the time to their local time.

The email reads: On January 7, 2016, Our Release Engineering team will deploy another release. To ensure another quality release, QA has requested that Engineering code freeze on January 5, 2016 at 11:59 pm EST (15 Hours from now)

Since the Code Freeze fluctuates, I setup a TextExpander snippet to calculate the hours until Code Freeze. All I need to do is to select the date, copy it, and then put the cursor where I want the data to appear, and type my abbreviation and BAM the hours appears.

This is what the code looks like in TextExpander:

// Target Format: January 7, 2016 at 12:15 PM $clipboard = "%clipboard";
$releaseday = DateTime::createFromFormat('F j, Y at H:i A', $clipboard);
$today = new DateTime(now);

$diff = $today->diff($releaseday);
$hours = $diff->h;
$hours = $hours + ($diff->days*24);

echo $hours . " hours";


My abbreviation for this snippet is: release.hours

Since I am the only one that will be using this feature, I didn't put in any data validation in the PHP script. However, it's certainly best practice to have some additional validation in case someone selects an invalid entry.

The really cool thing is the I can create multiple snippets and have the hours display different hours based on a target location.



Add Comments




I find TextExpander, by Smile on My Mac, to be an awesome productivity tool. This past winter, I posted some cool snippets that demonstrate the power of the application. Occasionally, I will post some new snippets that I think will be useful in anyone's TextExpander library.


WednesdaySnagIt for QA
SaturdayInternet Tools
SundayOpen Topic
Monday Media Monday