 |
| Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

September 18th, 2004, 02:01 PM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Extracting info from dates
Hi
I would like to know How do I extract the Minutes or seconds etc from a given date. ex: if the Date is "18/9/2004 7:58:43 PM" , How do I extract the Minutes [i.e. 58] from the date and assign to another variable.
Thx
Praveen.
|
|

September 18th, 2004, 03:47 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
|
|
|
|

September 18th, 2004, 04:14 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Hello Moharo,
I don't see how that would help Praveen with his problem.
Praveen,
If the date format is always like that, you could try a function like this:
Code:
function getMinutes($date)
{
$minutes = explode(":",$date);
return $date[1];
}
$minutes = getMinutes($your_date_variable);
HTH!
-Snib <><
http://www.snibworks.com
There are only two stupid questions: the one you don't ask, and the one you ask more than once :-)
|
|

September 19th, 2004, 09:59 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Snib
sorry for being uninformative.. this is what i meant:
function getTheJuicyMeat($date)
{
$date = getdate(strtotime($date));
return $date["minutes"]; // if you want the minutes
// return $date["seconds"]; // if you want seconds
}
you can substitute "getTheJuicyMeat" with anything you like :)
peace
www.campusgrind.com the college portal
|
|

September 20th, 2004, 01:56 AM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi
I have 2 time values ,i.e. 11:09 am and 11:45 am, Now How do I get the difference between these two values i.e. 36 minutes?
Thanks
Praveen.
|
|

September 20th, 2004, 02:40 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
|
|
The easiest thing to do is use two complete dates i.e. Monday, September 20, 2004 11:09 AM and Monday September 20, 2004 11:45 AM, convert those dates to unix time and subtract one from the other.
Unix time is the number of seconds elapsed since the Epoch (00:00:00 UTC January 1, 1970). Once you have the difference between the two that number will be the number of seconds of difference between the two dates, then it's a matter of converting that number to a sensible time measurement.
HTH!
Regards,
Rich
--
[ http://www.smilingsouls.net]
[ http://pear.php.net/Mail_IMAP] A PHP/C-Client/PEAR solution for webmail
|
|

September 20th, 2004, 06:30 AM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thx for the reply ,
My dates are : 04:41:23 1-20-2004 , the Unix Time stamp is :1095635478,
04:19:40 1-20-2004 , the Unix time Stamp is : 1095677340 Now I would like to have the Difference of the above 2 unix time stamps, ideally I should get 22 minutes ,when I subtract the second value from the first one I get a value of -41862 [a negative value] . Please let me know How do I get the correct difference and also if Iam wrong any where.
Thx.
Praveen
|
|
 |