SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: mySQL Dates

  1. #1
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    If I understand correctly, to get the date, its CURDATE();

    How do I then set the date according to time zones?

    Thank You
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Assuming your machine is set to GMT

    CURDATE() + INTERVAL 10 HOUR

    Will give you the date for whatever time zone is GMT +10

    CURDATE() - INTERVAL 3 HOUR

    etc...

  3. #3
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    That means...the code would be:

    $sql = "INSERT INTO Accounts SET ".
    "Username='hello', ".
    "Date=CURDATE() + INTERVAL 13 HOUR";

    right?
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That looks pretty good

    Here's a tip. White space is ignored in sql as it is in HTML so you can just as easily write:
    Code:
    $sql = "INSERT INTO Accounts 
                 SET Username = 'hello',
                        Date = CURRDATE() + INTERVAL 13 HOUR";
    If you think that is more readable, easier to code. BTW, GMT + 13, is that Singapore time?

    Actually, it wasn't indented that much when I typed it - damned vB.

  5. #5
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LOL
    I don't really get your readability tip. =)
    Yep..According to my host's settings, I have to set the time +13 hours to be Singapor etime! =)

    thanks for your help!
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  6. #6
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hOW DO i KNOW IF THE SERVE RIS SET TO gmt?
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    Monmouth Junction, NJ
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ask the host lol well figure out what time it is in greenwich right now and than check the timing on your servers?

  8. #8
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes..Thanks..I think I fugured that out already! lol

    okie..I have a problem.
    I want to insert the date/time into a mysql database.

    So instead of VARCHAR...i choose DATETIME is it?
    How then do I insert into the database field?
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  9. #9
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    Monmouth Junction, NJ
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    uh just go ahead and toss in mediumtext and place the date in there or you can use the timestamp

  10. #10
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Timestamp?
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein


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
  •