Solarpitch Posted February 3, 2008 Share Posted February 3, 2008 Hey, If I have a variable that contains the date like... $today = "3-02-08"; ... is there anyway I can convert the date to this format from this variable... 20080203 <--- excatly like that Thanks. Quote Link to comment Share on other sites More sharing options...
Aureole Posted February 3, 2008 Share Posted February 3, 2008 If you mean, convert a time-stamp into an actual readable date then you're looking for date(), if you mean change the date into a time-stamp then I think you want mktime(). <?php // Example... $timestamp = "12859325"; $time= date( 'l jS M Y, g:i a', $timestamp ); echo( $time ); ?> Quote Link to comment Share on other sites More sharing options...
Solarpitch Posted February 3, 2008 Author Share Posted February 3, 2008 Right, I see what you mean. I am starting to wonder if there are issues with the date function in php 4? I have the below function that will take a start time and a finish time and bascially loop through start to finish producing 15min intervals in between. When I test this on php5 it works fine, however on php4 it wont populate the combo box with the generated loop list. Thats why I am afraid to try using the way you specified <?php function get_lunch_time($lunch_start, $lunch_finish){ $st = strtotime(date('Y-m-d') . $lunch_start); $en = strtotime(date('Y-m-d') . $lunch_finish); $int = 15 * 60; // number of seconds in 15 minutes $select = "<select name=\"time\" id='listboxes' >"; for ($i = $st; $i <= $en; $i += $int) { $time = date('h:i a',$i) . "<br>\n"; $select .= "<option value=\"".$time."\">".$time."</option>"; } $select .= "</select>"; return $select; } ?> Quote Link to comment Share on other sites More sharing options...
Solarpitch Posted February 3, 2008 Author Share Posted February 3, 2008 Sorry guys but I am still not getting this. How can I convert "05-02-08" to "20080205" .. I've been messign around with strtotime and the rest of the functions... the closest I got was the 1970's :-\ Quote Link to comment Share on other sites More sharing options...
alecks Posted February 3, 2008 Share Posted February 3, 2008 $date = strtotime(05-02-08); $date = date('Ydm'); i think should do it, play with the format... Quote Link to comment Share on other sites More sharing options...
Solarpitch Posted February 3, 2008 Author Share Posted February 3, 2008 Thanks, but that wont convert it.. it will only display todays date in the 20080203 format Quote Link to comment Share on other sites More sharing options...
CerealBH Posted February 3, 2008 Share Posted February 3, 2008 thats the way 2 convert it... strtotime then u convert it with date... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.