Results 1 to 9 of 9

Thread: Date issue

  1. #1

    Thread Starter
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Date issue

    Hai friends,

    i just want to calculate employee work hours.
    i use the following method and work well it seems.
    is this method i am using is professional php way? if not, please tell what type of problem can be occour?

    example :

    Code:
    $timein=09:10:00;
    $timeout=22:20:00;
    $workhrs=$timeout-$timein;

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Date issue

    I don't know what PHP version you're using, but that code is invalid.
    There is no date literal syntax.

    This'll work in most newer versions:
    PHP Code:
    $timein strtotime('09:10:00');
    $timeout strtotime('22:20:00');

    $workhrs strftime('%I:%M:%S'$timeout $timein);

    echo 
    $workhrs
    Note that PHP versions 5.1.0 and above running in strict standards mode will throw a warning if no default time zone is set before using any of the date/time functions. You can set this in php.ini, or using the date_default_timezone_set function.

  3. #3

    Thread Starter
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Date issue

    Quote Originally Posted by penagate
    I don't know what PHP version you're using, but that code is invalid.
    There is no date literal syntax.

    This'll work in most newer versions:
    PHP Code:
    $timein strtotime('09:10:00');
    $timeout strtotime('22:20:00');

    $workhrs strftime('%I:%M:%S'$timeout $timein);

    echo 
    $workhrs
    Note that PHP versions 5.1.0 and above running in strict standards mode will throw a warning if no default time zone is set before using any of the date/time functions. You can set this in php.ini, or using the date_default_timezone_set function.
    Pana, thanks for the codes. before i try it,
    actually my php version is 4.4.4
    my date substraction code in the first post really works
    i dont no y.

    ill try your code. it seems the professinal method.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Date issue

    I didn't know it worked in 4.4. I tried it in 6 and it didn't, so it's probably deprecated and should be avoided.

  5. #5

    Thread Starter
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Date issue

    ok

  6. #6

    Thread Starter
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Date issue

    pana
    in
    Code:
    $workhrs = strftime('%I:%M:%S', $timeout - $timein);
    what is '%I:%M:%S' tells? what is the usage of % sign in php?

    please.

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Date issue


  8. #8

    Thread Starter
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Date issue

    strftime(), yes now i undestood pana,
    i ll come back.

  9. #9

    Thread Starter
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Date issue

    pana, i have some problem with your code. it shows invalid tot hours.

    time_in | time_out | total_hours
    08:00:00 | 16:00:00 | 3

    Code:
    $temp_time_in=strtotime($timein); 
    $temp_time_out=strtotime($timeout); 
    //calculate total hours of work
    $tothr = strftime('%I', $temp_time_out - $temp_time_in);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width