#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    I've written a program that searches
    a dbase file for the user's password
    and id and if it matches, writes info
    to screen - I have written a function
    which I put at the bottom of my code
    to format the date and return the
    formatted date as a string -
    but I can't get this working. Can
    anyone please tell me what I've done wrong.

    /****************************************/
    /* GRAB FIELDS UPLOADED FROM FORM */
    /****************************************/

    $sTempID = Trim($TheUserID);
    $sTempPass = Trim($ThePassword);

    /****************************************/
    /* FIELD #'S IN DATABASE */
    /****************************************/

    $Field_Status = 0;
    $Field_ID = 1;
    $Field_AccType = 2;
    $Field_Bal = 3;
    $Field_TotHrs = 4;
    $Field_LastHrs = 5;
    $Field_BalAsOf = 6;
    $Field_RenewDate = 7;
    $Field_Pass = 8;

    /****************************************/
    /* OPEN THE DATABASE */
    /****************************************/

    $dbname = "bal";
    $iReadonly = 0;
    $bOpened = 0;
    $iNumRecords = 0;
    $iCount = 0;
    $bFound = false;

    $bOpened = dbase_open ($dbname, $iReadonly);

    if (! $bOpened)
    {
    print "Can't open database.";
    exit;
    }

    /****************************************/
    /* TRY TO FIND RECORD */
    /****************************************/

    $iNumRecords = dbase_numrecords($bOpened);

    for ($iCount=1; $iCount <= $iNumRecords; $iCount++)
    {
    $sTempRec = dbase_get_record($bOpened, $iCount);

    if ((Trim($sTempRec[$Field_ID]) == $sTempID) && (Trim($sTempRec[$Field_Pass]) == $sTempPass))
    {
    $bFound = true;
    break;
    }
    }

    /****************************************/
    /* IF RECORD IS NOT FOUND... */
    /****************************************/

    if (! $bFound)
    {
    print "not found <br>";
    dbase_close($bOpened);
    exit;
    }

    if ($bFound)
    {
    $sBal = FormatDate((string) $sTempRec[$Field_BalAsOf]);
    $sRenew = FormatDate((string) $sTempRec[$Field_RenewDate]);

    print "$sBaln";
    print $sRenewn";
    }

    dbase_close($bOpened);

    /****************************************/
    /* F U N C T I O N S */
    /****************************************/

    function FormatDate($sTempDate)
    {
    $sYear = substr($sTempDate, 0, 4);
    $sMonth = substr($sTempDate, 4, 2);
    $sDay = substr($sTempDate, 6, 2);

    $sDate = $sMonth . "/" . $sDay . "/" . $sYear;

    return $sDate;
    }

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    7
    Rep Power
    0
    what up kathyc,
    well..... first off what is the variable you are passing to it? what is $sTemplate? is it a Unix Time Stamp... a javascript document.write... that would help to know more about the variable.

    i do this....... i know it is over kill but it works

    $year = substr($datefromdb,0,4);
    $mon = substr($datefromdb,4,2);
    $day = substr($datefromdb,6,2);
    $hour = substr($datefromdb,8,2);
    $min = substr($datefromdb,10,2);
    $sec = substr($datefromdb,12,2);
    $orgdate = date( "l F dS, Y h:i A",mktime($hour,$min,$sec,$mon,$day,$year));
    echo "<b>Date:</b> $orgdaten";

    hope that helps
    ccbcreg

    /****************************************/
    /* F U N C T I O N S */
    /****************************************/

    function FormatDate($sTempDate)
    {
    $sYear = substr($sTempDate, 0, 4);
    $sMonth = substr($sTempDate, 4, 2);
    $sDay = substr($sTempDate, 6, 2);

    $sDate = $sMonth . "/" . $sDay . "/" . $sYear;

    return $sDate;
    }

    [/B][/QUOTE]

  4. #3
  5. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,645
    Rep Power
    4492
    For both of you, if you are trying to chop up a MySQL date, then you need to look into the DATE_FORMAT() function in mysql. it will save you a lot of time. it's exactly like the date() function in PHP, except that it works on a mysql timestamp, instead of a unix_timestamp. check out the details in the MySQL manual. Chapter 7.4.11 Date and Time functions, I think.

    ---John Holmes...

    ------------------
    *************************************************************
    * The manual can probably answer 90% of your questions...
    *
    * PHP Manual. www.php.net/manual
    * MySQL Manual: www.mysql.com/documentation/mysql/bychapter
    *************************************************************

IMN logo majestic logo threadwatch logo seochat tools logo