PHP Date Manipulation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • walnutmon

    PHP Date Manipulation

    All, first post, very exciting

    I have a list of dates that are given in the form of a two dimentional
    array.

    Ex.

    var $timeOfYear = array(
    1 =array(
    'name' ='begining',
    'start' ='1/1',
    'end' ='5/31'
    ),
    2 =array(
    'name' ='end',
    'start' ='6/1',
    'end' ='12/31'
    ),
    3 =array(
    'name' ='special fun time',
    'start' ='3/21',
    'end' ='6/20'
    )
    );

    Now, I want to take the current date and find what period it falls
    into. Obviously, this is a very simple case and will be more
    complicated in practice... Note that some periods overlap, in this
    case we fall into the shortest period.

    My idea was to sort the array from shortest period to longest, then
    iterate until I find a match. I don't really know the best way to do
    that in PHP. Thanks in advance!
  • Jerry Stuckle

    #2
    Re: PHP Date Manipulation

    walnutmon wrote:
    All, first post, very exciting
    >
    I have a list of dates that are given in the form of a two dimentional
    array.
    >
    Ex.
    >
    var $timeOfYear = array(
    1 =array(
    'name' ='begining',
    'start' ='1/1',
    'end' ='5/31'
    ),
    2 =array(
    'name' ='end',
    'start' ='6/1',
    'end' ='12/31'
    ),
    3 =array(
    'name' ='special fun time',
    'start' ='3/21',
    'end' ='6/20'
    )
    );
    >
    Now, I want to take the current date and find what period it falls
    into. Obviously, this is a very simple case and will be more
    complicated in practice... Note that some periods overlap, in this
    case we fall into the shortest period.
    >
    My idea was to sort the array from shortest period to longest, then
    iterate until I find a match. I don't really know the best way to do
    that in PHP. Thanks in advance!
    >
    Check out usort(). You can define the function that sorts the array to
    be whatever you want.

    One thought - what do you do if an element spans the end of the year?
    Or the end of February (this is a leap year, after all).

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    Working...