Announcement

Collapse
No announcement yet.

PHP Newbie need a little help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • jeffct
    replied
    If you have the date stored in MySQL as a MySQL date field, there is no need to hack up some PHP code to convert everything, MySQL has built in functions to format a date.

    Check manual:
    http://www.mysql.com/

    Leave a comment:


  • Mark Hensler
    replied
    I prefer date() over getdate().

    Leave a comment:


  • Mark Hensler
    replied
    And how would that work? That just returns UNIX timestamps.

    Leave a comment:


  • RINCE
    replied
    Couldn't you just use the strtotime function for this?

    Leave a comment:


  • Mark Hensler
    replied
    Age calc...
    Snippet from my site (that FireFly had fun with)
    Code:
    // SELECT UNIX_TIMESTAMP(birthday) FROM table_name WHERE ...
    // $birthday
    
    $tmp        = time() - $birthday;
    $years      = floor($tmp / 31557600);
    $tmp        = floor($tmp % 31557600);
    $days       = floor($tmp / 86400);
    $tmp        = floor($tmp % 86400);
    $hours      = floor($tmp / 3600);
    $tmp        = floor($tmp % 3600);
    $minutes	= floor($tmp / 60);
    
    // stop FireFly from hacking my age   ;)
    unset($age);
    
    $printed_and = FALSE;
    if ($minutes > 1) {
        $age = ", and $minutes minutes" . $age;
        $printed_and = TRUE;
    }
    else if ($minutes == 1) {
    	$age = ", and $minutes minute" . $age;
        $printed_and = TRUE;
    }
    if ($hours != 0) {
        $age = ($printed_and) ? ", $hours hours" . $age : ", and $hours hours" . $age;
        $printed_and = TRUE;
    }
    else if ($hours == 1) {
        $age = ", and $hours hour" . $age;
        $printed_and = TRUE;
    }
    if ($days != 0) {
        $age = ($printed_and) ? ", $days days" . $age : ", and $days days" . $age;
    }
    else if ($days == 1) {
        $age = ", and $days day" . $age;
        $printed_and = TRUE;
    }
    $age = "$years years" . $age;

    Leave a comment:


  • scoutt
    replied
    1) you are better off on saving it to the DB in the format you want.

    or you have to exploded each one.
    $your_date = yyyy-mm-dd
    $ex = explode("-", $your_date);

    that will put it in an array to so you can have it displayed however you want.

    2)
    $ex = now();
    echo $ex;

    3) I am thinking you have to have the dates compared so in ordered to do that they will have to be the same. yyyy.mm.dd

    Leave a comment:


  • Santa
    started a topic PHP Newbie need a little help

    PHP Newbie need a little help

    Hi there,

    first sorry for my bad english, my german is much better

    OK I started with php 1 week ago so my knowing about php arnt that great.
    I have a MySQL database, where I have a field for date in this format (yyyy-mm-dd) so what I have to to, to get this date on my Page in this format (dd-mm-yyyy or better dd.mm.yyyy) ?


    2.)
    How can I say a String in a PHP Page it should have the NOW-Date-Time in this format ( yyyy-mm-dd 00:00:00) ?

    3.) As I told u in my first question I have a date (birthday) in my MySQL DB so how is the script to get a Age from this date to the Now-Date . I mean the script should write on the Page, This user is now XX Years old.

    I hope u can help me.

    Thx and greetings from germany

    Xyla
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Working...
X