Yii Framework Forum: Saving Date In Oracle - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Saving Date In Oracle Rate Topic: -----

#1 User is offline   sandeep kaushik 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 22-August 13

Posted 18 November 2013 - 04:00 AM

Hi friends, I am using oracle database. I am saving date and time in a field using extension for calendar. My problem is that I can save time only from 1 to 12. When I try to use to_date or to_timestamp nothing comes up and framework does not accept. Please help me.
0

#2 User is offline   Raciel 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 04-July 17

Posted 05 July 2017 - 03:28 PM

Hi:
I´m usign Yii2 with oracle db, and in the table, I have a field type DATE that contains the date and time of the INSERT RECORD.

The problem is, when I try to show it in the gridview or detailview widget...
I tried to doit with the use of 'yii\i18n\Formatter' in the main configuration, like this

'formatter' => [
    'class' => 'yii\i18n\Formatter',
    'dateFormat' => 'php:d/m/Y',
    'datetimeFormat' => 'php:d/m/Y H:i:s',
    'timeFormat' => 'php:H:i:s',
    'nullDisplay' => '-',
],



and in the index view like this

 <?= GridView::widget([
      (...)
      columns => [
         'dateField:datetime',
         (...)
       ],
 ])?>



but all I get in the view is "25/06/2017 00:00:00", I DON'T KNOW WHY ???
when i do the "select to_char(dateField, 'DD/MM/YYYY HH24:MI:SS') from temp" i get '25/06/2017 22:50:20' and this is what i need to get.

how can i do it rigth.
i need some help
thanks.
0

#3 User is offline   Arockia Johnson SR 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 192
  • Joined: 25-June 13
  • Location:Singapore

Posted 11 July 2017 - 04:00 AM

Hi Raciel,

Have you tried this?


$date = DateTime::createFromFormat("d#M#y H#i#s*A", $agr->CREATED_DATE);
echo $date->format('M d,Y');



Because I also using Oracle database type DATE. The above snippet works fine for me!
மகிழ்ச்சியாக குறியிடுங்கள்!..... Happy Coding!.....


Thanks & Regards,
ஜான்சன் ( Arockia Johnson SR )
www.arojohnson.tk

Hit (+) button If my replies really helped you!
1

#4 User is offline   Raciel 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 04-July 17

Posted 07 August 2017 - 01:02 PM

View PostArockia Johnson SR, on 11 July 2017 - 04:00 AM, said:

Hi Raciel,

Have you tried this?


$date = DateTime::createFromFormat("d#M#y H#i#s*A", $agr->CREATED_DATE);
echo $date->format('M d,Y');



Because I also using Oracle database type DATE. The above snippet works fine for me!


Hi.... , I'm sorry for the delay in answering you ... I take some time before check my account..., and I already solved the problem... what you should do is to define the format in the connection string in my case will be like this...

'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'oci:dbname=//xxxxx:1521/xxxx',
            'username' => 'xxxx',
            'password' => 'xxx',
            'charset' => 'utf8',
            'on afterOpen' => function ($event) {
                $event->sender->createCommand("ALTER SESSION SET NLS_DATE_FORMAT = 'MM/DD/YYYY HH24:MI:SS'")->execute();
            }
        ]


this way you can use the other code like i used in the last post
thanks for all
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users