Solved

Need to parse out unix timestamp from these values  -

Posted on 2012-03-21
5
234 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
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AJAX Wordpress Not Reading Variable 2 55
PHP 5.6 and 7.x 4 37
How to get this library to work load? 8 37
MySQL Persistent Connections 10 30
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…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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 dynamically set the form action using jQuery.

713 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