Convert variables

Posted on 2004-11-11
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';

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
Question by:justaphase
    LVL 48

    Accepted Solution

    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.
    LVL 27

    Expert Comment

    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);
    LVL 1

    Author Comment

    And again... it was so easy...

    Thank you...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    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…
    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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now