SitePoint Sponsor |
|
User Tag List
Results 1 to 13 of 13
-
Apr 14, 2007, 19:53 #1
- Join Date
- Nov 2005
- Location
- Karachi - Pakistan
- Posts
- 1,134
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Some Help required about date and Time
Hi
Please note that in my HTML form i have 6 text boxes, that is
Day1, Month1, Year1,
and
Day2, Month2, Year2,
both the sets are used to get the Date of birth from the user.
Now in PHP i want to do following :
1 - i want to concatinate the Day,Month,Year to create a date object.
2 - When both the sets are concatinated to represent 2 different dates, i want to determint the younger of them .
3 - I want to determine the age in years and in months from both the dates.
Please guide me in this regards !!
Zeeshan
-
Apr 14, 2007, 20:40 #2
- Join Date
- Apr 2007
- Posts
- 1,205
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
There is no date object per se in PHP. You can get a Unix timestamp integer like this:
PHP Code:$date = mktime(0,0,0,$month,$day,$year);
-
Apr 14, 2007, 21:16 #3
- Join Date
- Nov 2005
- Location
- Karachi - Pakistan
- Posts
- 1,134
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok this way how can i get the age of both the persons in years ?
moreover, how can i get their DOB ? can i do this
echo date('d-m-Y',$date);
please guide
-
Apr 14, 2007, 21:48 #4
- Join Date
- Dec 2006
- Location
- /dev/swat
- Posts
- 619
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Salam,
I am not clear about ur post...
R U recieve the day, month, year from select boxes seperatly.
-
Apr 14, 2007, 22:10 #5
- Join Date
- Nov 2005
- Location
- Karachi - Pakistan
- Posts
- 1,134
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Walaykum assallam WarehmatAllah
I have text boxes for the Day, Month and Year. User put the day, month and year by typing.
Now i want to convert the THREE textbox values to form a PHP date. And then i want to know the User age in months and years.
Please guide.
-
Apr 14, 2007, 22:25 #6
- Join Date
- Dec 2006
- Location
- /dev/swat
- Posts
- 619
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok 1st of all nice to meet u on sitepoint.
I will suggest u to make select boxes for day, month, and year.
Then use php varaibles for to make a date.
How let me explain...
day (textbox or select box) from html form
PHP Code:$day=htmlentities($_POST['day']);
$month=htmlentities($_POST['month']);
$year=htmlentities($_POST['year']);
This is for security purpose that a user cannot enter some specail characters.
like (./><~!).hope u got it.
If u want to use mysql db then for db use like this.
PHP Code:$day=mysql_real_escape_string($_POST['day']);
After all of that now u have to make date in from above $day,$month,$year.
make a new variable in php under the above variables:
PHP Code:$date=$year"-"$month"-"$day;
-
Apr 14, 2007, 23:26 #7
Hi -
I'm a newb. w/ php, so perhaps am off -
but was wondering if this would work:
PHP Code:$day1=$_POST ['year1'];
$month1=$_POST ['year1'];
$year1=$_POST ['year1'];
$day2=$_POST ['year2'];
$month2=$_POST ['year2'];
$year2=$_POST ['year2'];
PHP Code:$dob1 = $day1.'-';
$dob1 .= $month1.'-';
$dob1 .= $year1;
//repeat as $dob2 for the 2's...
Good luck,
ElF-Fox 2.0 :: WIN :: el design :: US
-
Apr 14, 2007, 23:29 #8
- Join Date
- Dec 2006
- Location
- /dev/swat
- Posts
- 619
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Oh sorry i forgot :
Try this:
PHP Code:$date=$year."-".$month."-".$day;
-
Apr 15, 2007, 02:08 #9
- Join Date
- Nov 2005
- Location
- Karachi - Pakistan
- Posts
- 1,134
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
i have already done that all.
But that will concat the TEXTs not converthing them to DATE. I want that to be converted in to date, so that i can perform some other Date operations on it.
-
Apr 15, 2007, 05:06 #10
something like this:
PHP Code:$date=strtotime("04-06-2005"); //example date
echo date('d',$date)."-".date('m',$date)."-".date('Y',$date);
my mobile portal
ghiris.ro
-
Apr 15, 2007, 08:23 #11
- Join Date
- Nov 2005
- Location
- Karachi - Pakistan
- Posts
- 1,134
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi
thanks for all the replys. Please note that when the user enter theyr date of birth by filing the DAY / MONTH and YEAR text boxes. Then i want to know when its next Birthday is comming ? is it in next 60 days, is it in next 180 days ? or it is next year ? this is waht i want to achieve.
Please help.
-
Apr 16, 2007, 08:11 #12
- Join Date
- Nov 2005
- Location
- Karachi - Pakistan
- Posts
- 1,134
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
is there any one who may figure out the solution ?
-
Apr 16, 2007, 12:01 #13
Countdown timer
PHP Code:function time_until($event, $day, $month, $year = "unset", $min = 0, $hour = 0, $sec = 0){
/**
* The above prints the time until a given date.
* This can calculate to any time of day.
*/
/**
* If you didn't put a year above ($year = "unset"), assume it's the current year
*/
if ($year == "unset")
$year = date("Y");
$left = mktime($sec, $min, $hour, $month, $day, $year) - mktime();
/**
* Lets assum that this is an annual event such as a Birthday and that
* it will happen again next year. This starts the counter over again after
* the event takes place.
*/
if (0 > $left)
$left = mktime($sec, $min, $hour, $month, $day, $year + 1) - mktime();
/**
* If there is no time left on the counter (the day has come)
* Change the "My" if you want, but leave the $event for the event name
* This is set so it will say: "My Birthday"
*/
if ($left == 0)
return "My $event";
$time = array(
"year" => 31449600,
"week" => 604800,
"day" => 86400,
"hour" => 3600,
"minute" => 60,
"second" => 1);
$ret_str = "There ";
while(list($span, $scale) = each($time)){
$chunk = floor($left / $scale);
$left = $left % $scale;
if ($chunk != 0):
/**
* if there is more than one day left, have are, for 1 day have is
*/
$p1 = ($chunk == 1) ? "is" : "are";
if ($chunk > 1)
$span = "${span}s";
$sep = ($left == 0) ? " and " : ", ";
$ret_str .= ((!ereg("[0-9]", "$ret_str")) ? $p1 : $sep) .
" $chunk $span";
endif;
}
return $ret_str . " until my ${event}.";
}
$birthday="1965-04-05"; //my birthday ;-)
$date= explode('-', $birthday);
/**
*("Event", day of month, month);
*/
echo time_until("Birthday", $date[2], $date[1]);
my mobile portal
ghiris.ro
Bookmarks