SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Date Problem

  1. #1
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello, I have this script here, for to make lists in a form with day, month and year. It works fine. But now I will have another one of this, where the init. value is 14 days later. So if I just make this : $day = $datarr[0]+14 , it works fine for the day, but it doesn't really do the job in case we are at the ende of the month, because it does not change the month. So how can make it that the month will be 1 more in case the day goes from 31th to 1st.
    Thanx for help.

    <?PHP
    $end=date("d.m.Y");
    $datarr = explode(".",$end);
    $day = $datarr[0];
    $month = $datarr[1];
    $year = $datarr[2];

    echo " <table width='250' border='0' cellspacing='0' cellpadding='0'>
    <tr>
    <td width='50'>
    <select name='endetag'>";
    for ($i=1; $i<=31; $i++) {
    echo "
    <option ";
    if ($i==$day) echo " selected ";echo "value='$i'>$i."; }
    echo "
    </select>&nbsp;
    </td>
    <td width='50'>
    <select name='endemonat'>";
    for ($i=1; $i<=12; $i++) {
    echo "
    <option ";
    if ($i==$month) echo " selected ";echo "value='$i'>$i."; }
    echo "
    </select>&nbsp;
    </td>
    <td width='150'>
    <select name='year'>";
    for ($i=1; $i<=3; $i++) {
    echo "
    <option ";
    $jahr = $jahrheute-1+$i;
    if ($i==$jahrheute) echo " selected ";echo "value='$jahr'>$jahr"; }
    echo "
    </select>
    </td>
    </tr>
    </table>";
    ?>

  2. #2
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you should use date function instead of adding 14 to the date[]

    //Today
    $end=date("d.m.Y");
    $datarr = explode(".",$end);
    $day = $datarr[0];
    $month = $datarr[1];
    $year = $datarr[2];

    //14 days later
    $end=date("d.m.Y",time()+14*86400);
    $datarr = explode(".",$end);
    $day = $datarr[0];
    $month = $datarr[1];
    $year = $datarr[2];
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  3. #3
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I checked it and get this date: 1.1.01
    Is there anything else I have to change in the skript, or is it just to add this here: time()+14*86400 ?

  4. #4
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried it and get:

    $end=date("d.m.Y",time()+14*86400);
    => 24.03.2001 (today is 10.03.2001)

    How did you check it? That's weird how you got 1.1.01 (which is not even the format "d.m.Y")
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  5. #5
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I got it like this : 1.1.0
    Here is my skript again:

    <?PHP

    $end=date("d.m.Y",time()+14*86400);
    $datarr = explode(".",$ende);
    $day = $datarr[0];
    $month = $datarr[1];
    $year = $datarr[2];



    echo " <table width='250' border='0' cellspacing='0' cellpadding='0'>
    <tr>
    <td width='50'>
    <select name='endetag'>";
    for ($i=1; $i<=31; $i++) {
    echo "
    <option ";
    if ($i==$day) echo " selected ";echo "value='$i'>$i."; }
    echo "
    </select>&nbsp;
    </td>
    <td width='50'>
    <select name='endemonat'>";
    for ($i=1; $i<=12; $i++) {
    echo "
    <option ";
    if ($i==$month) echo " selected ";echo "value='$i'>$i."; }
    echo "
    </select>&nbsp;
    </td>
    <td width='150'>
    <select name='endejahr'>";
    for ($i=1; $i<=3; $i++) {
    echo "
    <option ";
    $jahr = $jahrheute-1+$i;
    if ($i==$year) echo " selected ";echo "value='$jahr'>$jahr"; }
    echo "
    </select>
    </td>
    </tr>
    </table>";


    ?>
    Sorry, there are some german words in it.
    Jahr = Year,
    Tag = Day,
    Month = Monat
    ..quite similar, isn't it?

  6. #6
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm sorry, I just found my mistake:

    $end=date("d.m.Y",time()+14*86400);
    $datarr = explode(".",$ende);

    $end and $ende, I just forgott the "e".
    It's working fine now.
    Thank you for helping, Alex

  7. #7
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad you got it.
    so skript is like "script" in English? I guess so Interesting. I hope I could learn German someday!
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  8. #8
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alex ???


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
  •