Advanced Search

Results 1 to 3 of 3

Thread: Saving Dates in mysql

  1. #1
    Join Date
    Nov 2007
    Posts
    149
    Thanks
    67
    Thanked 0 Times in 0 Posts

    Default Saving Dates in mysql

    Hi,

    I want to save the date of 10 days after the current date in my MySQL DB.

    For example:
    if today is 29/09/2013 I want to save in my db the date: 09/10/2013

    How can I do it?

    Thanks!

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,154
    Thanks
    261
    Thanked 690 Times in 678 Posts

    Default

    This is a several step process.

    You can get the current time using:
    time()

    Then you can add 10 days:
    time() + 60*60*24*10

    Then you can use that value (save it in a variable) in the date function:
    date('FORMAT',$savedtime)

    Replace "format" with the appropriate format (anything you want, see the php.net manual for more info).


    However, in general it's a bad idea to save dates in a human-readable format in a database. Instead, just save the timestamps. Then do whatever you want with them in PHP-- and format them, using date(), when you display them.

    Doing math on raw dates is confusing and indirect. But doing math on timestamps is easy.



    By the way, if you do happen to need to convert a string/description/text to a timestamp, then you can use:
    strtotime()
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,624
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by djr33 View Post
    By the way, if you do happen to need to convert a string/description/text to a timestamp, then you can use:
    strtotime()
    Like
    PHP Code:
    $timestamp strtotime'10 days' ); 
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  4. The Following User Says Thank You to traq For This Useful Post:

    djr33 (09-29-2013)

Similar Threads

  1. Saving date in mysql db
    By d-machine in forum PHP
    Replies: 3
    Last Post: 02-23-2013, 08:09 PM
  2. Saving XML file to Mysql Database
    By newphpcoder in forum MySQL and other databases
    Replies: 0
    Last Post: 10-18-2011, 09:22 AM
  3. Saving to mySQL and XML in PHP
    By Tissy in forum PHP
    Replies: 1
    Last Post: 10-01-2011, 01:52 AM
  4. different dates
    By james438 in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 06-09-2010, 06:35 AM

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
  •