# Date Format

**URL:** <https://www.ruby-forum.com/t/date-format/139480>\
**Category:** Rails\
**Created:** [June 4, 2008, 10:32am UTC](https://www.ruby-forum.com/t/date-format/139480 "2008-06-04T10:32:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wawa88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/b5a626/32.png) [@wawa88](https://www.ruby-forum.com/u/wawa88)\
**Post date:** [June 4, 2008, 10:32am UTC](https://www.ruby-forum.com/t/date-format/139480/1 "2008-06-04T10:32:07Z")

</div>

Now i facing the date format in my  
database. I am using mysql as my database then the datetime format is  
2008-06-04 15:17:55. But my datetime format is like this Fri May 23  
16:43:28 +0800 2008. So when i execute it say incorrect datetime value.  
how do i change the date\_format or should i change the datatype to  
string instead.

Actually i generate a scaffold in rails like these:

ruby script/generate scaffold MSISDN:string datetime:datetime  
description:text

and after that i rake the migrate folder and it generate a schema.rb.

Now how do i change the schema.rb attribute.

Thanks.

Wawa

---

<div class="post-metadata">

**Author:** ![wawa88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/b5a626/32.png) [@wawa88](https://www.ruby-forum.com/u/wawa88)\
**Post date:** [June 4, 2008, 10:43am UTC](https://www.ruby-forum.com/t/date-format/139480/2 "2008-06-04T10:43:51Z")

</div>

Emmie W. wrote:

> Now i facing the date format in my  
> database. I am using mysql as my database then the datetime format is  
> 2008-06-04 15:17:55. But my datetime format is like this Fri May 23  
> 16:43:28 +0800 2008. So when i execute it say incorrect datetime value.  
> how do i change the date\_format or should i change the datatype to  
> string instead.

If you store date, the DateTime is the right format. Changing iit to  
string isn’t a good idea.

temp = DateTime.parse(“Fri May 23 16:43:28 +0800 2008”)  
should give you a valid DateTime object which you can assign to your db  
column

> Now how do i change the schema.rb attribute.

You don’t make changes in schema. If yo want to change something in your  
db, just write another migration

---

<div class="post-metadata">

**Author:** ![wawa88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/b5a626/32.png) [@wawa88](https://www.ruby-forum.com/u/wawa88)\
**Post date:** [June 4, 2008, 11:11am UTC](https://www.ruby-forum.com/t/date-format/139480/3 "2008-06-04T11:11:23Z")

</div>

Thanks a lot. But is there another way not to hard code  
temp = DateTime.parse(“Fri May 23 16:43:28 +0800 2008”) as I am  
retrieving emails in rails so the datetime will always change. is it a  
way to format it to same as the internet email format. Thanks

Wawa

---

<div class="post-metadata">

**Author:** ![wawa88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/b5a626/32.png) [@wawa88](https://www.ruby-forum.com/u/wawa88)\
**Post date:** [June 4, 2008, 11:40am UTC](https://www.ruby-forum.com/t/date-format/139480/4 "2008-06-04T11:40:37Z")

</div>

say your date is in any variable like @email\_date\_time  
then you can do  
DateTime.parse(@email\_date\_time)

---

<div class="post-metadata">

**Author:** ![wawa88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/b5a626/32.png) [@wawa88](https://www.ruby-forum.com/u/wawa88)\
**Post date:** [June 4, 2008, 6:20pm UTC](https://www.ruby-forum.com/t/date-format/139480/5 "2008-06-04T18:20:22Z")

</div>

I did not save in any variable as the datetime is i retrieved from  
internet email and save it into a text file. So there isn’t any variable  
assign to it. That why i do not what to do about changing the format of  
the datetime. Hope there is someone who know it. Thanks

Wawa
