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 4 of 4

Thread: Date/Time

  1. #1
    New Coder
    Join Date
    Aug 2003
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Date/Time

    I want to store dates and times in a database, and have one field in the table to store the actuall date, and have another determine how it is formatted. Then using php I want to display the date/time using the information provided in the database. How do I go about doing this?
    Last edited by Goober; 12-31-2003 at 02:20 AM.

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Use the date_format function, store how the person wants it show in the field, like D/M/Y, or m/d/Y, add % infront of each letter (%D/%M/%Y for example) then do something like this in the query

    SELECT DATE_FORMAT(datefield,'$user->dateformat') AS datefield WHERE user='$username'

  • #3
    New Coder
    Join Date
    Aug 2003
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts
    But what goes in the other field? (The one that stores the date/time informaion, and NOT the field that stores its format). And how do I recieve that information using a php script? (That information being current date/time).

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You'd use the date() function

    Depending on how your database field is

    date('Y-m-d')


  •  

    Posting Permissions

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