php time function

Discussion in 'PHP' started by googlehelper, Feb 20, 2009.

  1. #1
    i ran this cmd and i got this as output 2021-02-09 00:15:37

    $time=date("dmyHis", time());
    echo $time;

    also suggest me a better way to store timestamp in the mysql table through php
     
    googlehelper, Feb 20, 2009 IP
  2. dowhile

    dowhile Active Member

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #2
    with that you can get output only in format
    DDMMYYHHIISS
    DD - Day (01-31),
    MM - Month (01-12),
    YY - Year (00 - 99), two digits.
    HHIISS, hours-minutes-seconds

    So you can't get output like "2021-02-09 00:15:37"
    if you want to insert date/time in MySQL best format for that is
    'YYYY-MM-DD HH:mm:ss' or
    'YYYYMMDDHHmmss'

    in PHP you can get this with command
    $time = date('Y-m-d H:i:s',time());
    or
    $time = date('Y-m-d H:i:s',time());

    Also you can use MySQL function "NOW()" in insert statement.

    If your column is type of timestamp, as I recall you don't need to update values for that column types, since they are updated with every insert/update statement.
     
    dowhile, Feb 20, 2009 IP