SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 42 of 42
  1. #26
    SitePoint Zealot malluwood's Avatar
    Join Date
    Nov 2006
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Date display problem

    hi

    Thanks it is working smmothly.

    But i found one problem.Its not working for single digit dates,months input.if we r using two digit date and month its working fine.

  2. #27
    SitePoint Member Azhagiri's Avatar
    Join Date
    Nov 2006
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Date display problem

    hi malluwood,
    ya ur correct malluwood, it is not working for single digit days and month input, unless u r storing the date(days,month) with precedding zero's.

    i am working on it and will try to fix it as early as possible.
    thanks for ur comment.

    Bye....
    Have a nice weekend.

    Azhagiri
    India.

  3. #28
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    sprintf should solve that problem for you.

    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  4. #29
    SitePoint Zealot malluwood's Avatar
    Join Date
    Nov 2006
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up date display

    hi

    use the below code for solving single digit problem with dates
    enjoy

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    HTML Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>
    
    <body>
    <form name="form1" method="post" action="">
      <input type="text" name="date">
      <input type="submit" name="Submit" value="Submit">
    </form>
    </body>
    </html>
    PHP Code:
    $d=$_POST['date'];
    $a=split('-',"$d");
    if(
    strlen($a[0])==1)
    $a[0]='0'.$a[0];
    if(
    strlen($a[1])==1)
    $a[1]='0'.$a[1];
    print_r($a);
    ?> 
    Wood
    Last edited by malluwood; Nov 20, 2006 at 04:02.

  5. #30
    SitePoint Zealot malluwood's Avatar
    Join Date
    Nov 2006
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Quote Originally Posted by Azhagiri
    hi anil and group members,

    from all the discussions above i got what anil is looking for and i found out the solution for it. the code will be little bit to long. i have given the comment line where ever it is needed. hope every one can understand. by seeing this code if any one find solution with minimal code plz discuss with the same heading or if u feel difficult in understanding plz enquire with me.

    **********************************************
    Cod for the date display: (this will help if data type is varchar)
    ***********************************************

    PHP Code:
    $query_Newss "SELECT id,`date` FROM nande WHERE type=news"
    $Newss mysql_query($query_Newss$GBC) or die(mysql_error());
    $row_Newss mysql_fetch_assoc($Newss);
    $totalRows_Newss mysql_num_rows($Newss);
    $arrids= array();
    $arrdates= array();
    $mkarrays= array(); //for storing mktime
    $mkarrays1= array(); //for storing mktime, future reference
    $results=array();
    $arrdatees= array();
    $is=0;
    do
     {
       
    $arrids[$is]=$row_Newss['id'];
       
    $arrdates[$is]=$row_Newss['date'];
       
    $is++;
      }while(
    $row_Newss mysql_fetch_array($Newss));
     
    //code for splitting the date
     
    $cnts1=count($arrdates);
     for(
    $is=0;$is<$cnts1;$is++)
      {
        
    $strings1=$arrdates[$is];
        
    $arrdatees[$is]=substr($strings1,0,10); // for future reference
        
    $dds=substr($strings1,0,2); //for date
        
    $mms=substr($strings1,3,2); //for month
        
    $yys=substr($strings1,6,4); // for year
        
    $mkarrays[$is]= mktime(000$mms$dds$yys);
        
    $mkarrays1[$is]= mktime(000$mms$dds$yys);
        }
        
    asort($mkarrays);
        
    $sts=strftime("%m,%d,%Y"); // getting server time
        
    $sts1mktime(000$sts); // getting timestamp for server time
        // code for subtracting server time with the timestamp generated for value stored in database
        
    for($is=0;$is<$cnts1;$is++)
          {
                 
    $results[$is]=$sts1-$mkarrays1[$is];
          
          }
          
    asort($results); //sorting the subtracted value array
          
    natsort($results); // performing the natuaral sorting algortim for the result array
          
          // for diaplaying
          
    $afs=array();
          
    $afs=array_keys($results);
          
    $newarrs=array();
          for(
    $is=0;$is<$cnts1;$is++)
           {
             
    $newarrs[$is]=$results[$afs[$is]];
           }
           
    // for finding if same date exist in the database
           
    $zeroarrays=array();
           
    $kks=0;
           
    $mms=0;
           
    $finalarrs=array();
           
    $indexs=array();
           for(
    $is=0;$is<$cnts1;$is++)
            {
              if(
    $newarrs[$is]==0)
               {
                 
    $zeroarrays[$mms]=$is;
                 
    $mms++;
                }
             }
            
    $cntzerarrs=count($zeroarrays);
        if(
    $cntzerarrs==0)
        {  
          
    //finalarr will contain the result what we need
          
    for($is=0;$is<$cnts1;$is++)
           {
            
    $finalarrs[$is]= date("j-n-Y",($sts1-$newarrs[$is]));
            
           }
           
          
    print_r($finalarrs);
          
    // for getting the array index value. i.e not having o value
          
    for($is=0;$is<$cnts1;$is++)
           {
            for(
    $js=0;$js<$cnts1;$js++)
             {
              if(
    $finalarrs[$is]==$arrdatees[$js])
                 
    $indexs[$is]=$arrids[$js];
             }
          }
         } 
    //end of if cntzerarr=0 condition
         
    else
         { 
            for(
    $is=0;$is<$cntzerarrs;$is++)
             {
               
    $valuess=$zeroarrays[$is];
               
    $finalarrs[$is]= date("j-n-Y",($sts1-$newarrs[$valuess]));
               
    $kks=$is;
             }
            for(
    $is=0;$is<$cnts1;$is++)
              { 
                if(
    in_array($is,$zeroarrays))
                 {
                  
                  }
                  else
                   {
                     
    $kks=$kks+1;
                     
    $finalarrs[$kks]= date("j-n-Y",($sts1-$newarrs[$is]));
                    }
              }
             for(
    $is=0;$is<$cnts1;$is++)
              {
                for(
    $js=0;$js<$cnts1;$js++)
                 {
                    if(
    $finalarrs[$is]==$arrdatees[$js])
                      
    $indexs[$is]=$arrids[$js];
                  }
              }
         
         }
    // end of else
         
        
    $lastids=$indexs[0];
        
    $listings "SELECT id, news, details, `date`, image, title, type FROM nande WHERE type='news' and id='$lastids'";
        
    $listings1mysql_query($listings$GBC) or die(mysql_error());
        
    $listings2 mysql_fetch_assoc($listings1); 
    see i have display only the latest date in lastids. if u want the forthcoming date to be displayed then use the loop to select the query and display it.



    hope it will solve the date problem.

    Bye....
    Azhagiri
    India
    /

  6. #31
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post

    hai

    Thanks once agin

    Can we do this same with MySql.In php we have to write lot of codes.if we use mysql query for this we can finish in a line.Can any body help me in this ?


    Thanks

  7. #32
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,338
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    in mysql, use the DATE_FORMAT function
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  8. #33
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up date display

    how can i apply dateformat with this concept ?

  9. #34
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,338
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    which concept?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  10. #35
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    date display

  11. #36
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,338
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    have you looked at the DATE_FORMAT function in the manual?

    its whole purpose is date display!!
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  12. #37
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    But i am not geeting my particular display format using date format function

  13. #38
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,338
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by aniltc
    But i am not geeting my particular display format using date format function
    what did you try? what format do you want?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  14. #39
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    the order of the dates which i have stored in the database is

    5-9-2006

    10-10-2006

    12-10-2006

    14-11-2006

    16-12-2006

    02-02-2006

    15-12-2006

    I want to display as

    15-12-2006

    16-12-2006

    02-02-2006

    14-11-2006

    12-10-2006

    10-10-2006

    5-9-2006

    I am getting this format using php

    But i want to know how can i acheive this with Mysql using date_format()

    Thanks

  15. #40
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,338
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    do me a favour, please

    tell me what you get for this query --
    Code:
    select count(*) from yourtable
     where datecolumn = '2006-12-15'
    you will have to substitute the real table and column names
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  16. #41
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    hi
    by executing ur query i am getting zero as the result.

    bcz the format u have given is different from the format we are storing in the database.

    select count(*) from yourtable
    where datecolumn = '15-12-2006'
    if i use the above query i am getting the o/p as 1


  17. #42
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,338
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    i asked you earlier in this thread what the datatype of the column is

    you replied that it is date, but obviously it isn't -- it's probably VARCHAR

    you will never get your results correctly until you actually store your dates in a DATE datatype column

    sorry, but that's what you will have to do
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •