Solved

Need to parse out unix timestamp from these values  -

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
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…

896 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

18 Experts available now in Live!

Get 1:1 Help Now