Solved

Need to parse out unix timestamp from these values  -

Posted on 2012-03-21
5
236 Views
Last Modified: 2012-03-22
On my old server, I had the code below that someone put together for me.

Now that I have updated to a new server with php5 it no longer works.

I need to take the values below and turn them into unix time.
 
This is a part of a much larger script, which figures timezones. It's not updating to dst, and this seems to be the root of the problem. Right now, if I echo '$dst_start', I get nothing.

Any ideas on how to do this?

Thanks,   Chris


<?php

//pulled out of db

$start_day= '2nd Sunday';
$start_hour='2';
$start_month='March';
$start_year='2012';

//put into unix time

$dst_start=strtotime($start_day." ".$start_hour.":00", strtotime("1 $start_month $start_year"));

echo $dst_start;

?>
0
Comment
Question by:St_Aug_Beach_Bum
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 12

Expert Comment

by:larsrohr
ID: 37751061
It looks like this works in php5:
  $start_day= 'second Sunday';

But this does not:
  $start_day= '2nd Sunday';
0
 
LVL 12

Expert Comment

by:larsrohr
ID: 37751074
You can easily translate your strings with numerical ordinals into strings with ordinals as words:
$start_day= '2nd Sunday';
$ordinals_numeric = array("1st", "2nd", "3rd", "4th", "5th");
$ordinals_alpha = array("first", "second", "third", "fourth", "fifth");
$start_day = str_replace($ordinals_numeric, $ordinals_alpha, $start_day);

Open in new window


I'm assuming that you don't need to go higher than "5th" in this case.
0
 
LVL 8

Accepted Solution

by:
Ahmed Merghani earned 500 total points
ID: 37751076
Also you can do it by removing "nd" in the "2nd Sunday" in the $start_day variable like this:
<?php

//pulled out of db

$start_day= '2 Sunday';
$start_hour='2';
$start_month='March';
$start_year='2012';

//put into unix time

$dst_start=strtotime($start_day." ".$start_hour.":00", strtotime("1 $start_month $start_year"));

echo $dst_start;

?>

Open in new window

0
 

Author Closing Comment

by:St_Aug_Beach_Bum
ID: 37752635
Thanks - just updated the database, changing the 1st and 2nds to 1 and 2, working great.

Should have thought of trying that myself, just didn't occur to me :)
0
 

Author Comment

by:St_Aug_Beach_Bum
ID: 37752645
Thank you both for your answers, went with this last one, but I think either would have worked.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question