SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: timestamp

  1. #1
    SitePoint Addict Banana Man's Avatar
    Join Date
    Dec 2005
    Posts
    389
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    timestamp

    Hi,

    Im working with timestamps for the first time so just want to check something.

    If i have a time stamp ( $timestamp ) and want to add a certain amount of time is this how its done?

    Add 5 hours: $timestamp + (5 * 60 * 60)

    Add 2 mins: $timestamp + (0 * 2 * 60)

    Thanks

  2. #2
    SitePoint Zealot Bill Palmer's Avatar
    Join Date
    Oct 2005
    Location
    London, UK
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://php.net/strtotime

    Check "Example 440. A strtotime() example".

    Might be a little easier for you.

  3. #3
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,933
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Banana Man View Post
    Add 2 mins: $timestamp + (0 * 2 * 60)
    Multiplying something by zero always yields a zero result.

  4. #4
    SitePoint Addict Banana Man's Avatar
    Join Date
    Dec 2005
    Posts
    389
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Ok, then ive got the concept all wrong. How would you go about adding 2 minutes to a timestamp?

  5. #5
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,933
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    2*60 = 120
    but
    0*2*60 = 0

    Pretty primary school really!

  6. #6
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just be aware that manually adding seconds to your time stamp won't take daylight savings into account when the before/after date crosses a transition from when daylight savings is in effect.

  7. #7
    SitePoint Addict Banana Man's Avatar
    Join Date
    Dec 2005
    Posts
    389
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cranial-bore View Post
    Just be aware that manually adding seconds to your time stamp won't take daylight savings into account when the before/after date crosses a transition from when daylight savings is in effect.
    Thats a good point actually. It wont affect this function but something to take into account in the future.

  8. #8
    SitePoint Evangelist mrwooster's Avatar
    Join Date
    Jan 2006
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have a look at the date and time functions in the PHP manual, when I started using dates I found that they were very cumbersome, but actually, there are loads of functions built into PHP which make date and time manipulation easy.


Bookmarks

Posting Permissions

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