Page 1 of 1
convert 3 variables into timestamp format
Posted: Wed Jan 05, 2011 11:09 pm
by chrismicro
ok here is the problem
I have 3 numbers for hour, day, and month
example:
$aud1hour = "09";
$aud1day = "15";
$aud1month = "10";
basically meaning 9:00am, Oct, 15th
whats the easiest way to take those varibles and convert them to this format with the least amount of code, even if the varibles chage, i need a function that converts it quickly.
remember the format must be:
hour, Month, Day like: 9:00am, Oct, 15th
Re: convert 3 variables into timestamp format
Posted: Thu Jan 06, 2011 12:22 am
by chrismicro
this still has issues:
the hour format is 00 -23
the day format is 0-31
month format is from 01-12
$aud1hour = "00";
$aud1day = "20";
$aud1month = "09";
$hour = date('GA',mktime($aud1hour));
$month = date('F',mktime($aud1month));
$day = date('jS',mktime($aud1day));
echo "<font face='geneva, arial, sans serif' size='2' color='#00FF00'>".$month.", ".$day." - ".$hour."</font>";
will show:
January, 6th - 0AM...weird..any help would be great, make note the month day hour are the only variables i have to work with
Re: convert 3 variables into timestamp format
Posted: Thu Jan 06, 2011 12:33 am
by thecodewall
Maybe this can help.
From my program:
Code: Select all
$day = $_POST['expiry_date_day'];
$month = $_POST['expiry_date_month'];
$year = $_POST['expiry_date_year'];
$date = date('Y-m-d',strtotime($year.'-'.$month.'-'.$day));
$query="INSERT INTO stock (code, name, expirydate, category, count)
VALUES('$_POST[code]','$_POST[name]','$date','$_POST[category]','$_POST[count]')";
mysql_query($query) or die(mysql_error());
http://codewall.blogspot.com
Re: convert 3 variables into timestamp format
Posted: Thu Jan 06, 2011 4:34 pm
by pickle
Look up how mktime() is used. It expects 6 parameters, not just one. You likely want something like this:
Code: Select all
$stamp = mktime(0,0,0,$aud1month,$aud1day,date('Y'));
$formatted_date = date('g:ia, M jS',$stamp);
Re: convert 3 variables into timestamp format
Posted: Fri Jan 07, 2011 12:37 pm
by chrismicro
This worked:
$stamp = mktime($aud1hour,0,0,$aud1month,$aud1day,0);
$formatted_date = date('g:ia, M jS',$stamp);
Thanks for all your help guys