?
Solved

Convert variables

Posted on 2004-11-11
3
Medium Priority
?
216 Views
Last Modified: 2012-06-22
I'm trying calculate time between dates(with mktime).

$dateDiff = mktime(16,33,00,11,11,2004) - mktime(16,30,44,11,11,2004);
echo 'Difference in seconds: ' . $dateDiff . '<br />';

echo '<br />Years Difference   = '. floor($dateDiff/365/60/60/24);
echo '<br />Months Difference  = '. floor($dateDiff/60/60/24/7/4);
echo '<br />Weeks Difference   = '. floor($dateDiff/60/60/24/7);
echo '<br />Days Difference    = '. floor($dateDiff/60/60/24);
echo '<br />Hours Difference   = '. floor($dateDiff/60/60);
echo '<br />Minutes Difference = '. floor($dateDiff/60);

The problem is, if i save the information: 16,33,00,11,11,2004 in the MsSQL Data Base in a char field when i get it to put inside the mktime like:

$TimeStamp = '16,30,44,11,11,2004';
mktime($TimeStamp)

it doesn't work... mabe i should split like this:

list($Hour, $Minutes, $Seconds, $Months, $Day, $Year) = split('[,]', $TimeStamp);

and then convert them to integer... Can anyone help me?

thx in advanced
0
Comment
Question by:justaphase
3 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
ID: 12556919
If you have that format, use the method you described. You don't need to convert them to integer (this will be done by PHP) and then use those variables in mktime like this:
mktime($Hour, $Minutes, $Seconds, $Months, $Day, $Year);
There are a lot of other way, but they willl end up in such function call.
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12556946
If you are going to do it with list i would use explode instead, split uses regular expressions and is more then is needed here:

list($Hour, $Minutes, $Seconds, $Months, $Day, $Year) = explode(",", $TimeStamp);
0
 
LVL 1

Author Comment

by:justaphase
ID: 12557067
And again... it was so easy...

Thank you...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question