Results 1 to 3 of 3

Thread: php date problem

  1. #1
    Join Date
    Mar 2007
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question php date problem

    hi, i have a form in which the user has to enter a date in the format dd-mm-yyyy. it can be any date. i want to store the previous day in my database.
    eg: if the date entered is 01-01-2009 then the new date that should be entered to data base should be 31-12-2008.
    can some one pls help me with this.
    thanks in advance..
    suk..

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    PHP Code:
    $date '31-12-2008';
    $date strtotime($date);
    $date $date-(3600*24//Minus one day in seconds
    echo date('d-m-Y',$date); 
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    A day isn't precisely 24 hours.
    Code:
    $date = date('Y-m-d', strtotime('2008-01-01 -1 days'));
    Use international date format where possible, it makes working with dates easier.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •