Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need to parse out unix timestamp from these values  -

Posted on 2012-03-21
5
Medium Priority
?
238 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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.
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

688 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