Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts

    storing the current date and time in mysql table

    hi,


    i have a table called date_time.it has 2 fields.
    field-name datatype
    1.date date
    2.time time

    i want to store the current date and current time in that table.when ever i fetch the date and time it should display the current date and current time.any of your idea will be appreciated

    thanks
    mrjameer

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts
    You use the date() function to get both the date and time. There is no need to store this if you always want to retrieve the current date and time though - you just call it whenever you need it. If however you want to store the date and time at the time when the database record was updated, then simply assemble it in whatever format you want using the date() function and store it as normal.

  • #3
    Regular Coder
    Join Date
    Aug 2006
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi,




    when a user will upload files on my site,the file info will be stored in table.and it will also shows a link to the user to download or visit that file.when he visits the link,the counter in table will be incremented.on every day at a particular time i want to update the counter to zero.that's all

    thanks
    mrjameer

  • #4
    New Coder
    Join Date
    May 2007
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    hi.....

    Hi friend,

    usee.........just now() function in the insert table......it will work

    for example.......

    Insert into tablename (column1,column2,time.) VALUES ('$_post[columnname1]','$coulmnname2',now()).....

    this works defiently....

  • #5
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    This query should do it for you:

    $query = "INSERT INTO `date_time` (`date`,`time`) VALUES (DATE(),TIME())";

    (enlarging on what nani_s23 said)

    conversely, you could just have one field for the date AND time, and use the MySQL function NOW() to get the whole timestamp.

    For more, check out http://dev.mysql.com/doc/refman/5.0/...l#function_now

    HTH
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #6
    New to the CF scene
    Join Date
    May 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have always used

    PHP Code:
    putenv("TZ=EST5EDT"); // Eastern Time 
    //putenv("TZ=AST9ADT"); // Alaskan Time
    //putenv("TZ=PST8PDT"); // Pacific Time
    //putenv("TZ=MST7MDT"); // Mountain Time
    //putenv("TZ=CST6CDT"); // Central Time
    //putenv("TZ=GMT0"); // Greenwich Mean Time
    //putenv("TZ=UTC0"); // Universal Time Coordinated 
    This is because normally, at least when I was learning PHP, time() only used the system time.

    Using the putenv() function, time() reflects the time for the timezone you would like for it to use.

    If this is wrong, someone please correct me.

    PM

  • #7
    New Coder
    Join Date
    Feb 2006
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    personally have always used now()

    seems to work the best.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •