Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
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
 
Old September 18th, 2004, 02:01 PM
Authorized User
 
Join Date: Aug 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to spraveens
Default 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.

 
Old September 18th, 2004, 03:47 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Moharo
Default

use the get_date() function.....

http://pl.php.net/manual/en/function.getdate.php



www.campusgrind.com the college portal
 
Old September 18th, 2004, 04:14 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

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 :-)
 
Old September 19th, 2004, 02:00 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Use the strtotime function, this tries to create a Unix timestamp from any date string. Once you have a Unix timestamp you can format it any way you like using the date function.

http://www.php.net/strtotime
http://www.php.net/date

HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
[http://pear.php.net/Mail_IMAP] A PHP/C-Client/PEAR solution for webmail
 
Old September 19th, 2004, 09:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Moharo
Default

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
 
Old September 20th, 2004, 01:56 AM
Authorized User
 
Join Date: Aug 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to spraveens
Default

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.
 
Old September 20th, 2004, 02:40 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

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
 
Old September 20th, 2004, 06:30 AM
Authorized User
 
Join Date: Aug 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to spraveens
Default

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






Similar Threads
Thread Thread Starter Forum Replies Last Post
extracting attribute value hag XSLT 1 March 3rd, 2008 03:16 AM
Extracting Text Jeff Mason BOOK: Beginning Regular Expressions 1 October 24th, 2006 06:38 AM
extracting atributes - how to do this? zoreli XML 6 August 12th, 2006 03:46 AM
Getting info from database -between dates doranaz Classic ASP Databases 2 December 23rd, 2003 01:02 AM
Where would I get info on how to download info aidanc ASP.NET 1.x and 2.0 Application Design 1 September 29th, 2003 02:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.