Date format as dd-mmm-yyyy, e.g. 18-JAN-2017?

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
accora
User
Posts: 46

Date format as dd-mmm-yyyy, e.g. 18-JAN-2017?

Post by accora »

Hello there,

Is it possible to set the date format like dd-mmm-yyyy, e.g. 18-JAN-2017?
The important thing is to have the month as three letters instead of just numbers.

My script uses the following file (phpmaker 2017):

phplocale/en.json

{
"date": "2016-08-22",
"version": "13.0.1",
"id": "en",
"locale": "en_GB",
"name": "English (Great Britain)",
"desc": "English (Great Britain, EN_GB)",
"author": "e.World",
"decimal_point": ".",
"thousands_sep": ",",
"mon_decimal_point": ".",
"mon_thousands_sep": ",",
"currency_symbol": "£",
"positive_sign": "",
"negative_sign": "-",
"frac_digits": 2,
"p_cs_precedes": 1,
"p_sep_by_space": 0,
"n_cs_precedes": 1,
"n_sep_by_space": 0,
"p_sign_posn": 1,
"n_sign_posn": 1,
"date_sep": "\/",
"time_sep": ":",
"date_format": "dmY",
"time_zone": ""
}


mobhar
User
Posts: 11702

Post by mobhar »

Try to put this code in "Language_Load" server event:

global $EW_DATE_FORMAT;
$EW_DATE_FORMAT = "dd-mmm-yyyy";


Webmaster
User
Posts: 9427

Post by Webmaster »

Avoid modifying $EW_DATE_FORMAT to custom format or some functions will not work in expected way. If you only need to show the dates in your preferred format in List/View page, use Row_Rendered server event (see Server Events and Client Scripts in the help file), e.g.

$this->MyDateField->ViewValue = date("MyFormat", strtotime($this->DateField->CurrentValue));

Read http://php.net/manual/en/function.date.php for format string.


accora
User
Posts: 46

Post by accora »

Thank you, I put this code in the Row_Rendered and it works well:

$this->ActionDate->ViewValue = date("d-M-Y", strtotime($this->ActionDate->CurrentValue));


mobhar
User
Posts: 11702

Post by mobhar »

Thanks for the info and thanks for letting us know how it works using PHP date() and strtotime() functions in "Row_Rendered" server event.


farichte
User
Posts: 30

Post by farichte »

Sorry for opening this up again,

I've used the row rendered
$this->MyDateField->ViewValue = date("MyFormat", strtotime($this->DateField->CurrentValue));

with format d F Y
and got an output like 1 October 2017

but, how can i change the date languange to another?
i''ve tried to change tools > languange and Page Option (Global) > General Option but it wont give me any result


sangnandar
User
Posts: 980

Post by sangnandar »

farichte wrote:
$this->MyDateField->ViewValue = date("MyFormat", strtotime($this->DateField->CurrentValue));
This is php function, using php locale.

farichte wrote:
i''ve tried to change tools > languange and Page Option (Global) > General Option
but it wont give me any result
This is apps language, using apps "locale" (xml language file).

Try Tools -> Locale Settings.

It works like this: when you use an xml language (don't change the language id in the file), it will then select the related (language_id).json file and set it as php locale.


farichte
User
Posts: 30

Post by farichte »

sangnandar wrote:

This is apps language, using apps "locale" (xml language file).

Try Tools -> Locale Settings.

It works like this: when you use an xml language (don't change the language id in the
file), it will then select the related (language_id).json file and set it as php
locale.

yes, thank you for replying
i've tried changing the locale setting but it doesn''t give me any difference. it still give me 'october'.


sangnandar
User
Posts: 980

Post by sangnandar »

Run this script against your php machine.
<?php
setlocale(LC_TIME, "C");
echo strftime("%A");
setlocale(LC_TIME, "fi_FI");
echo strftime(" in Finnish is %A,");
setlocale(LC_TIME, "fr_FR");
echo strftime(" in French %A and");
setlocale(LC_TIME, "de_DE");
echo strftime(" in German %A.\n");
?>

It should output: Monday in Finnish is maanantai, in French lundi and in German Montag.


farichte
User
Posts: 30

Post by farichte »

Thank You, it works!
i test it and it works when i use current time
but unfortunately, it wont work for the field which i used row rendered on
it still give me 'october'
any suggestion?

<?php
setlocale(LC_TIME, "id");
echo date('d F Y',(strtotime($tes->date->CurrentValue))); ?>

the workaround i got right now is using array replace to replace the english date
it's bulky but it works

function ind_df($timestamp = '', $date_format = 'l, j F Y ') {
if (trim ($timestamp) == '')
{
$timestamp = time ();
}
elseif (!ctype_digit ($timestamp))
{
$timestamp = strtotime ($timestamp);
}

remove S (st,nd,rd,th) there are no such things in indonesia :p

$date_format = preg_replace ("/S/", "", $date_format);
$pattern = array (
'/Mon[day]/','/Tue[sday]/','/Wed[nesday]/','/Thu[rsday]/',
'/Fri[day]/','/Sat[urday]/','/Sun[day]/','/Monday/','/Tuesday/',
'/Wednesday/','/Thursday/','/Friday/','/Saturday/','/Sunday/',
'/Jan[uary]/','/Feb[ruary]/','/Mar[ch]/','/Apr[il]/','/May/',
'/Jun[e]/','/Jul[y]/','/Aug[ust]/','/Sep[tember]/','/Oct[ober]/',
'/Nov[ember]/','/Dec[ember]/','/January/','/February/','/March/',
'/April/','/June/','/July/','/August/','/September/','/October/',
'/November/','/December/',
);
$replace = array ( 'Sen','Sel','Rab','Kam','Jum','Sab','Min',
'Senin','Selasa','Rabu','Kamis','Jumat','Sabtu','Minggu',
'Jan','Feb','Mar','Apr','Mei','Jun','Jul','Ags','Sep','Okt','Nov','Des',
'Januari','Februari','Maret','April','Juni','Juli','Agustus','Sepember',
'Oktober','November','Desember',
);
$date = date ($date_format, $timestamp);
$date = preg_replace ($pattern, $replace, $date);
$date = "{$date}";
return $date;
}


creat015
User
Posts: 79

Post by creat015 »

this code :

function ind_df($timestamp = '', $date_format = 'l, j F Y ') {
if (trim ($timestamp) == '')
{
$timestamp = time ();
}
elseif (!ctype_digit ($timestamp))
{
$timestamp = strtotime ($timestamp);
}

remove S (st,nd,rd,th) there are no such things in indonesia :p

$date_format = preg_replace ("/S/", "", $date_format);
$pattern = array (
'/Mon[day]/','/Tue[sday]/','/Wed[nesday]/','/Thu[rsday]/',
'/Fri[day]/','/Sat[urday]/','/Sun[day]/','/Monday/','/Tuesday/',
'/Wednesday/','/Thursday/','/Friday/','/Saturday/','/Sunday/',
'/Jan[uary]/','/Feb[ruary]/','/Mar[ch]/','/Apr[il]/','/May/',
'/Jun[e]/','/Jul[y]/','/Aug[ust]/','/Sep[tember]/','/Oct[ober]/',
'/Nov[ember]/','/Dec[ember]/','/January/','/February/','/March/',
'/April/','/June/','/July/','/August/','/September/','/October/',
'/November/','/December/',
);
$replace = array ( 'Sen','Sel','Rab','Kam','Jum','Sab','Min',
'Senin','Selasa','Rabu','Kamis','Jumat','Sabtu','Minggu',
'Jan','Feb','Mar','Apr','Mei','Jun','Jul','Ags','Sep','Okt','Nov','Des',
'Januari','Februari','Maret','April','Juni','Juli','Agustus','Sepember',
'Oktober','November','Desember',
);
$date = date ($date_format, $timestamp);
$date = preg_replace ($pattern, $replace, $date);
$date = "{$date}";
return $date;
}

where is it placed? i try to put in Language_Load error

thanks


Post Reply