convert 3 variables into timestamp format

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chrismicro
Forum Newbie
Posts: 21
Joined: Fri Nov 12, 2010 7:03 am

convert 3 variables into timestamp format

Post 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
chrismicro
Forum Newbie
Posts: 21
Joined: Fri Nov 12, 2010 7:03 am

Re: convert 3 variables into timestamp format

Post 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.",&nbsp;".$day."&nbsp;-&nbsp;".$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
Last edited by chrismicro on Thu Jan 06, 2011 1:00 am, edited 2 times in total.
thecodewall
Forum Commoner
Posts: 33
Joined: Sun Dec 26, 2010 8:37 am

Re: convert 3 variables into timestamp format

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: convert 3 variables into timestamp format

Post 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);
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
chrismicro
Forum Newbie
Posts: 21
Joined: Fri Nov 12, 2010 7:03 am

Re: convert 3 variables into timestamp format

Post 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
Post Reply