note 102730 added to function.date

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
<?php

/**
 *  YA date converter. This function does NOT check if the supplied date is legal; it works according to the GIGO principle.
 *
 *  @param  string  $date       the input date.
 *  @param  string  $format_in  the format in which the input date is supplied.  ASSERT( strlen( $date ) === strlen( $format_in ) )
 *  @param  string  $format_out the format in which the output date has to be returned.
 *  @return string              the date in the format of $format_out.
 */
function YA_date_converter( $date, $format_in, $format_out )
{
    $len = min( strlen( $date ), strlen( $format_in ) );
    for( $i = 0; $i < $len; ++$i ) {
        if( false !== ( $pos = strpos( $format_out, substr( $format_in, $i, 1 ) ) ) ) {
            $format_out = substr( $format_out, 0, $pos ) . substr( $date, $i, 1 ) . substr( $format_out, $pos + 1 );
        }
    }

    return $format_out;
}

//  Feel free to figure out how it works. :-)
echo YA_date_converter( '02-03-2011', 'dd-mm-yyyy', 'yyyymmdd'                              ), PHP_EOL;     //  20110302
echo YA_date_converter( '02-03-2011', '!@-#$-%^&*', '*&^%$#@!'                              ), PHP_EOL;     //  11023020
echo YA_date_converter( '02/03-2011', 'DD MM YYYY', 'the year is YYYY, month MM, day DD'    ), PHP_EOL;     //  the/year-is 2011, month 03, day 02
----
Server IP: 69.147.83.197
Probable Submitter: 62.195.52.58
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit        -- https://master.php.net/note/edit/102730
Del: integrated  -- https://master.php.net/note/delete/102730/integrated
Del: useless     -- https://master.php.net/note/delete/102730/useless
Del: bad code    -- https://master.php.net/note/delete/102730/bad+code
Del: spam        -- https://master.php.net/note/delete/102730/spam
Del: non-english -- https://master.php.net/note/delete/102730/non-english
Del: in docs     -- https://master.php.net/note/delete/102730/in+docs
Del: other reasons-- https://master.php.net/note/delete/102730
Reject      -- https://master.php.net/note/reject/102730
Search      -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.