SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Loggedin date

  1. #1
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Loggedin date

    Hi,
    I store date as 2007-06-01 11:39:04 in db for loggedin users.
    Now i am showing the login as last login: 01-06-2007 11:39:04 .
    How can i change the db date to the date above i mention as 01-06-2007 11:39:04.

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    From PHP:
    PHP Code:
    $datetime "2007-06-01 11:39:04";
    list(
    $date,$time) = split(" "$datetime);
    list(
    $y$m$d) = split("-"$date);
    echo 
    date('d-m-Y'mktime(0,0,0,$m,$d,$y)) . " " $time
    Does this help?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks mate.

    Its working like a charm.

  4. #4
    SitePoint Enthusiast mrsmiley's Avatar
    Join Date
    Jul 2004
    Location
    Melbourne
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its faster if you format it as it comes out of the database by using the date_format functions provided by your database. No need to run that php code every time you need to display a date as well.

    If the date in the database isn't stored in an actual datetime field, then you will need to cast it first to a datetime data type before you can use the format function. Either way, its still faster to do it in the db server as part of the sql statement when you extract it. Particularly if you have a lot of them to do.

  5. #5
    SitePoint Evangelist praetor's Avatar
    Join Date
    Aug 2005
    Posts
    479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can really use Date_Format in your query.

  6. #6
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rajug View Post
    From PHP:
    PHP Code:
    $datetime "2007-06-01 11:39:04";
    list(
    $date,$time) = split(" "$datetime);
    list(
    $y$m$d) = split("-"$date);
    echo 
    date('d-m-Y'mktime(0,0,0,$m,$d,$y)) . " " $time
    Does this help?
    why so complex?

    PHP Code:
    print date('d-m-Y'strtotime('2007-06-01 11:39:04')); 
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  7. #7
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks guys for comments yes i know that pulling from db as date_format is faster than any code,
    I am thinking to pull out it like this,but i will compare it with that code, which one is realable.

  8. #8
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks logic_earth.
    I like one line code.


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
  •