Solved

Need to parse out unix timestamp from these values  -

Posted on 2012-03-21
5
229 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
  • 2
  • 2
5 Comments
 
LVL 12

Expert Comment

by:larsrohr
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you both for your answers, went with this last one, but I think either would have worked.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

772 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now