SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    function date and mktime

    i want to get a certain date
    i use 3 select box first = year , second = month , third = day.

    then i want to make a combined date out of it to enter into a database.
    i have done
    $date = mktime(0,0,0,$Year,$Month,$Day);

    but now nothing seems to work, i think i have to make
    use the function date on the mktime(...) but i am not too sure,
    is it like $date= date(mktime(.....) )

    will be obligised is sum1one could help me.
    why do i always go out with the wrong guys

  2. #2
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First thing to check is your vars exist... I mean if they are coming from a select, just echo to check they're being set properly. Date is used to format a date.

    You also have mktime the wrong way round... it should be

    mktime(0,0,0,$day,$month,$year)

    http://www.php.net/manual/en/function.mktime.php
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2002
    Location
    Santa Fe, NM
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by uptown_girl
    i want to get a certain date
    i use 3 select box first = year , second = month , third = day.

    then i want to make a combined date out of it to enter into a database.
    i have done
    $date = mktime(0,0,0,$Year,$Month,$Day);

    but now nothing seems to work, i think i have to make
    use the function date on the mktime(...) but i am not too sure,
    is it like $date= date(mktime(.....) )

    will be obligised is sum1one could help me.
    I think the following is what you want:

    Code:
    $date = date ("Y-m-d", mktime ($Year, $Month, $Day))
    See http://www.php.net/manual/en/function.date.php for details...

  4. #4
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by weirdbeardmt
    First thing to check is your vars exist... I mean if they are coming from a select, just echo to check they're being set properly. Date is used to format a date.

    You also have mktime the wrong way round... it should be

    mktime(0,0,0,$day,$month,$year)

    http://www.php.net/manual/en/function.mktime.php
    Yes you have
    It's actually: mktime(0,0,0,$month,$day,$year)

    From manual:
    Warning: Note the strange order of arguments, which differs from the order of arguments in a regular UNIX mktime()
    Anyhow, do what weirdbeardmt suggested: print out the variables to see if they are properly set.

    -Helge

  5. #5
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Helge
    Yes you have
    stupid American way of printing the date
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  6. #6
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't want to even start counting on how many times I've done that stupid mistake too.

    -Helge

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    alright guys, i am doing this on a sample page now, to see if it will work but so far to na avail.

    after i select the dates on the select box
    i initialise them in date and mktime.
    this is what i have

    <?php

    $date_today = date("m-d-Y", mktime(0,0,0,$ThisDay,$ThisMonth,$ThisYear);
    $date_tomorrow = date ("m-d-Y", mktime(0,0,0,$NextDay,$NextMonth,$NextYear);
    echo" Today is $date_today";
    echo" Tomorrow is $date_ltomorrow";
    ?>

    i use the echo to see if it works but doesn't so far.

    even in the varibles if i get rid of the "d-m-Y" it still gives the same error message, that there is a parse error in the lines
    $date_today=...
    $date_tomorrow= ...

    plz can ye hlp me
    why do i always go out with the wrong guys

  8. #8
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you are missing closing brackets on each of those lines
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  9. #9
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    also need to check the variable name in this line echo" Tomorrow is $date_ltomorrow";
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  10. #10
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and check the order of your day/month/year cos you date it using m-d-Y but in yuor mktime you use d-m-y
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky


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
  •