php money_format 변환 - 미국 형식 화폐 / MySQL 일자포멧 / 요일확인
화폐단위로 표시하기
PHP에는 여러나라의 화폐 단위로 변경이 가능한 함수가 있다.
참고: http://php.net/manual/en/function.money-format.php
// and 10 digits for left precision
setlocale(LC_MONETARY, 'en_US');
echo money_format('%(#10n', $number) . "\n";
// ($ 1,234.57)
함수로 만들기
// ### Number change Money Format ##########
function getMoneyFormat($m_str)
{
setlocale(LC_MONETARY, 'en_US');
$m_str = money_format('%(#10.0n', $m_str);
return $m_str; }
// ### 함수 호출 #######
getMoneyFormat($t_amount);
또 다른 방법 => number_format() 함수
(윈도우 IIS+PHP의 경우money_foramt함수가 정의되지 않는다는 에러가 발생할 수 있습니다.)
number_format ( float 또는
number_format ( float $number , int $decimals = 0 , string $dec_point = "." , string $thousands_sep = "," ) : string |
함수로 만들기
// ### Number change Money Format ##########
|
$number = 1234.5678;
$en_number = getMoneyMormat($number);
// $1,234.57
<?php $numbers = array(0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009); foreach ($numbers as $number) print $number."->".number_format($number, 2, '.', ',')."<br>"; ?> 0.001->0.00 0.002->0.00 0.003->0.00 0.004->0.00 0.005->0.01 0.006->0.01 0.007->0.01 0.008->0.01
0.009->0.01 |
참고: number_format API Documentation
요일 확인하기
http://php.net/manual/en/function.date.php
http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=qna_function&wr_id=331063
// 요일 확인
//$today = "2011-06-28";
echo date('w', strtotime("2014-10-5"));
//결과 (일요일)
0
string date ( string $format
[, int $timestamp
= time() ] )
MySQL 일자 포멧 만들기
http://www.w3schools.com/sql/func_date_format.asp
Syntax :
DATE_FORMAT(date,format)
Example :
DATE_FORMAT(NOW(),'%m-%d-%Y')
DATE_FORMAT(NOW(),'%d %b %y')
DATE_FORMAT(NOW(),'%d %b %Y %T:%f')
Result :
11-04-2008
04 Nov 08
04 Nov 2008 11:45:34:243
Formats the date
value according to the format
string.
The following specifiers may be used in the format
string. The “%
” character is required before format specifier characters.
Specifier | Description |
---|---|
%a | Abbreviated weekday name (Sun ..Sat ) |
%b | Abbreviated month name (Jan ..Dec ) |
%c | Month, numeric (0 ..12 ) |
%D | Day of the month with English suffix (0th , 1st , 2nd , 3rd , …) |
%d | Day of the month, numeric (00 ..31 ) |
%e | Day of the month, numeric (0 ..31 ) |
%f | Microseconds (000000 ..999999 ) |
%H | Hour (00 ..23 ) |
%h | Hour (01 ..12 ) |
%I | Hour (01 ..12 ) |
%i | Minutes, numeric (00 ..59 ) |
%j | Day of year (001 ..366 ) |
%k | Hour (0 ..23 ) |
%l | Hour (1 ..12 ) |
%M | Month name (January ..December ) |
%m | Month, numeric (00 ..12 ) |
%p | AM or PM |
%r | Time, 12-hour (hh:mm:ss followed by AM or PM ) |
%S | Seconds (00 ..59 ) |
%s | Seconds (00 ..59 ) |
%T | Time, 24-hour (hh:mm:ss ) |
%U | Week (00 ..53 ), where Sunday is the first day of the week; WEEK() mode 0 |
%u | Week (00 ..53 ), where Monday is the first day of the week; WEEK() mode 1 |
%V | Week (01 ..53 ), where Sunday is the first day of the week; WEEK() mode 2; used with %X |
%v | Week (01 ..53 ), where Monday is the first day of the week; WEEK() mode 3; used with %x |
%W | Weekday name (Sunday ..Saturday ) |
%w | Day of the week (0 =Sunday..6 =Saturday) |
%X | Year for the week where Sunday is the first day of the week, numeric, four digits; used with %V |
%x | Year for the week, where Monday is the first day of the week, numeric, four digits; used with %v |
%Y | Year, numeric, four digits |
%y | Year, numeric (two digits) |
%% | A literal “% ” character |
% | x , for any “x ” not listed above |
Ranges for the month and day specifiers begin with zero due to the fact that MySQL permits the storing of incomplete dates such as '2014-00-00'
.
출처: https://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html