SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast ethe's Avatar
    Join Date
    Oct 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation need help with mktime and date field in sql!!!

    Hi there!

    I need to convert the output of the mktime() function and compare to a date field in a mysql db

    does anyone know how to convert this output!

    Example:
    Currentday: 1130364000 (this needs to be converted to 2005-10-27)

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    if you are pulling the first timestamp out of a database, use something like
    PHP Code:
    <?php

    // Query the database
    $q mysql_query("SELECT date, UNIX_TIMESTAMP(date) AS timestamp FROM table");
    $row mysql_fetch_array($q);

    // then use PHP's date() function :
    $date date("F j, Y, g:i a"$row['timestamp']);

    echo 
    "$row[date] = $date"// Will output : 2005-05-21 18:09:43 = May 21, 2005, 6:09 pm

    ?>
    or found this function on phpfreaks
    PHP Code:
    <?php
    function date_convert($date,$type){
      
    $date_year=substr($date,0,4);
      
    $date_month=substr($date,5,2);
      
    $date_day=substr($date,8,2);
      if(
    $type == 1):
          
    // Returns the year Ex: 2003
          
    $date=date("Y"mktime(0,0,0,$date_month,$date_day,$date_year));
      elseif(
    $type == 2):
          
    // Returns the month Ex: January
          
    $date=date("F"mktime(0,0,0,$date_month,$date_day,$date_year));
      elseif(
    $type == 3):
          
    // Returns the short form of month Ex: Jan
          
    $date=date("M"mktime(0,0,0,$date_month,$date_day,$date_year));
      elseif(
    $type == 4):
          
    // Returns numerical representation of month with leading zero Ex: Jan = 01, Feb = 02
          
    $date=date("m"mktime(0,0,0,$date_month,$date_day,$date_year));
      elseif(
    $type == 5):
          
    // Returns numerical representation of month without leading zero Ex: Jan = 1, Feb = 2
          
    $date=date("n"mktime(0,0,0,$date_month,$date_day,$date_year));
      elseif(
    $type == 6):
          
    // Returns the day of the week Ex: Monday
          
    $date=date("l"mktime(0,0,0,$date_month,$date_day,$date_year));
      elseif(
    $type == 7):
          
    // Returns the day of the week in short form Ex: Mon, Tue
          
    $date=date("D"mktime(0,0,0,$date_month,$date_day,$date_year));
      elseif(
    $type == 8):
          
    // Returns a combo ExL Wed,Nov 12th,2003
          
    $date=date("D, M jS, Y"mktime(0,0,0,$date_month,$date_day,$date_year));
      elseif(
    $type == 9):
          
    // Returns a combo Ex: November 12th,2003
          
    $date=date("F jS, Y"mktime(0,0,0,$date_month,$date_day,$date_year));
      endif;
      return 
    $date;
    };
    ?>
    (might be slight overkill though!)

    Cheers

    Spike

    Welcome to the forums btw!!!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Enthusiast ethe's Avatar
    Join Date
    Oct 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I'll try

    Thanx 4 fast reply!
    I'll wil try it and see what wil work best for me
    greetz
    Ethe


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
  •