i could convert dattime format like this without using ActiveRecord.
Select CONVERT(varchar(100), GETDATE(), 121)
but how can i convert datetime format when using ActiveRecord?
i could convert dattime format like this without using ActiveRecord.
Select CONVERT(varchar(100), GETDATE(), 121)
but how can i convert datetime format when using ActiveRecord?
Sorry if I don’t fully understand your question, but this might help: http://www.yiiframework.com/doc/cookbook/10/
for example:
CREATE TABLE [MyTable] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[submitDate] [datetime] NULL ,
CONSTRAINT [PK_com_jlh] PRIMARY KEY CLUSTERED
(
[id]
) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
if there is a record, it’s submitDate=“20100101 00:00:000”
if use sql script directly:
select submitDate=convert(char,querydate,120) from MyTable
i can get whatever datetime format i want with sqlserver function: convert()
20100101 00:00:000
2010-01-01 00:00:000
2010 Jan. 01 00:00:000
etc…
But when i use ActiveRecord, the datetime format is always like this:"2010 Jan. 01 00:00"
How can i make the same conversions using ActiveRecord?
Hi Singlewood,
I don’t think you can do this with ActiveRecord.
You can use the PHP date() function to format the date.
http://php.net/manual/en/function.date.php
In Yii, there is a class for date formatting, it’s the CDateFormatter
http://www.yiiframework.com/doc/api/1.0.11/CDateFormatter
I generally store dates as unix time-stamps in the DB, for me, that’s the more flexible way of dealing with dates.
HTH,
jmas