Hi all, I''ve a string "Mon Nov 20 00:00:00 UTC+0530 2006" in my database. I want to retrieve that in dd-mm-yyyy format. Please help me out. Thanks, -- Posted via ruby-forum.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
time.strftime( string ) => string Formats time according to the directives in the given format string. Any text not listed as a directive will be passed through to the output string. Format meaning: %a - The abbreviated weekday name (``Sun'''') %A - The full weekday name (``Sunday'''') %b - The abbreviated month name (``Jan'''') %B - The full month name (``January'''') %c - The preferred local date and time representation %d - Day of the month (01..31) %H - Hour of the day, 24-hour clock (00..23) %I - Hour of the day, 12-hour clock (01..12) %j - Day of the year (001..366) %m - Month of the year (01..12) %M - Minute of the hour (00..59) %p - Meridian indicator (``AM'''' or ``PM'''') %S - Second of the minute (00..60) %U - Week number of the current year, starting with the first Sunday as the first day of the first week (00..53) %W - Week number of the current year, starting with the first Monday as the first day of the first week (00..53) %w - Day of the week (Sunday is 0, 0..6) %x - Preferred representation for the date alone, no time %X - Preferred representation for the time alone, no date %y - Year without a century (00..99) %Y - Year with century %Z - Time zone name %% - Literal ``%'''' character t = Time.now t.strftime("Printed on %m/%d/%Y") #=> "Printed on 04/09/2003" t.strftime("at %I:%M%p") #=> "at 08:56AM" On 5月8日, 下午12时36分, Rahul Ha <rails-mailing-l...@andreas-s.net> wrote:> Hi all, > > I''ve a string "Mon Nov 20 00:00:00 UTC+0530 2006" in my database. > I want to retrieve that in dd-mm-yyyy format. > Please help me out. > > Thanks, > > -- > Posted viahttp://www.ruby-forum.com.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> time.strftime( string ) => string > > t = Time.now > t.strftime("Printed on %m/%d/%Y") #=> "Printed on > 04/09/2003" > t.strftime("at %I:%M%p") #=> "at 08:56AM"Hi, Yes, You are right, I can format using time.strftime(.. But my string "Mon Nov 20 00:00:00 UTC+0530 2006" is of varchar type. So first I have to convert it to date/time format and then use strftime method. How can do that. Thanks, -- Posted via ruby-forum.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rahul Ha wrote:>> time.strftime( string ) => string >> >> t = Time.now >> t.strftime("Printed on %m/%d/%Y") #=> "Printed on >> 04/09/2003" >> t.strftime("at %I:%M%p") #=> "at 08:56AM" > > Hi, > Yes, You are right, I can format using time.strftime(.. > But my string "Mon Nov 20 00:00:00 UTC+0530 2006" is of varchar type. > So first I have to convert it to date/time format and then use strftime > method. > How can do that. > Thanks,Hi, I found a method strptime that converts string to date in req. format. But it works for string like ''27/07/06''. How can convert "Mon Nov 20 00:00:00 UTC+0530 2006" string to date 20-11-2006 form. ############ require ''date'' start_date = ''27/07/06'' start_date = Date.strptime(start_date, ''%d/%m/%y'') ################# please help me out. Thanks, -- Posted via ruby-forum.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
irb(main):023:0> start_date = "Mon Nov 20 00:00:00 UTC+0530 2006" => "Mon Nov 20 00:00:00 UTC+0530 2006" irb(main):025:0> d= Date.strptime(start_date, ''%a %b %d %H:%M:%S %Z %Y'') => #<Date: 4908119/2,0,2299161> irb(main):026:0> d.strftime => "2006-11-20" Regards, Dave _______________________________ Information and Educational Technology Kwantlen University College - 604-599-2120 "So powerful is the light of unity that it can illuminate the whole earth." --Bahá''u''lláh Rahul Ha <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> Sent by: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 08-05-2007 02:02 AM Please respond to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org cc Subject [Rails] Re: How to getDate Rahul Ha wrote:>> time.strftime( string ) => string >> >> t = Time.now >> t.strftime("Printed on %m/%d/%Y") #=> "Printed on >> 04/09/2003" >> t.strftime("at %I:%M%p") #=> "at 08:56AM" > > Hi, > Yes, You are right, I can format using time.strftime(.. > But my string "Mon Nov 20 00:00:00 UTC+0530 2006" is of varchar type. > So first I have to convert it to date/time format and then use strftime > method. > How can do that. > Thanks,Hi, I found a method strptime that converts string to date in req. format. But it works for string like ''27/07/06''. How can convert "Mon Nov 20 00:00:00 UTC+0530 2006" string to date 20-11-2006 form. ############ require ''date'' start_date = ''27/07/06'' start_date = Date.strptime(start_date, ''%d/%m/%y'') ################# please help me out. Thanks, -- Posted via ruby-forum.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> irb(main):023:0> start_date = "Mon Nov 20 00:00:00 UTC+0530 2006" > => "Mon Nov 20 00:00:00 UTC+0530 2006" > irb(main):025:0> d= Date.strptime(start_date, ''%a %b %d %H:%M:%S %Z %Y'') > => #<Date: 4908119/2,0,2299161> > irb(main):026:0> d.strftime> => "2006-11-20" > _______________________________Hi David, Yes It worked, Many thanks. Can we change the format and display it in dd-mm-yyyy format ? also can we do it reversely, like "2006-11-20" date to "Mon Nov 20 00:00:00 UTC+0530 2006" ? Thanks and regards -- Posted via ruby-forum.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yes It worked, Many thanks. Can we change the format and display it in> dd-mm-yyyy format ? also can we do it reversely, > like "2006-11-20" date to "Mon Nov 20 00:00:00 UTC+0530 2006" ?Hi , I''ve tried it like, ################## t = ''Mon Nov 20 00:00:00 UTC+0530 2006'' d= Date.strptime(t, ''%a %b %d %H:%M:%S %Z %Y'') date = d.to_s year, month, day = date.split(/-/) month = month.sub(/^0/,'''') puts day + "/" + month + "/" + year ########################## ==> 20/11/2006 It is working. Can we convert it again to "Mon Nov 20 00:00:00 UTC+0530 2006" ? :~} Regards, -- Posted via ruby-forum.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sure. You can get it back with d.strftime(''%a %b %d %H:%M:%S %Z %Y'') require ''date'' t = ''Mon Nov 20 00:00:00 UTC+0530 2006'' d= Date.strptime(t, ''%a %b %d %H:%M:%S %Z %Y'') date = d.to_s year, month, day = date.split(/-/) month = month.sub(/^0/,'''') puts day + "/" + month + "/" + year puts d.strftime(''%a %b %d %H:%M:%S %Z %Y'') On May 8, 10:49 pm, aveo <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Yes It worked, Many thanks. Can we change the format and display it in > > > dd-mm-yyyy format ? also can we do it reversely, > > like "2006-11-20" date to "Mon Nov 20 00:00:00 UTC+0530 2006" ? > > Hi , > I''ve tried it like, > ################## > t = ''Mon Nov 20 00:00:00 UTC+0530 2006'' > d= Date.strptime(t, ''%a %b %d %H:%M:%S %Z %Y'') > date = d.to_s > year, month, day = date.split(/-/) > month = month.sub(/^0/,'''') > puts day + "/" + month + "/" + year > ########################## > ==> 20/11/2006 > > It is working. Can we convert it again to "Mon Nov 20 00:00:00 UTC+0530 > 2006" ? > :~} > > Regards, > > -- > Posted viahttp://www.ruby-forum.com.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Something screwy with the time zone name though... Dave Dave wrote:> Sure. You can get it back with > d.strftime(''%a %b %d %H:%M:%S %Z %Y'') > > require ''date'' > > t = ''Mon Nov 20 00:00:00 UTC+0530 2006'' > d= Date.strptime(t, ''%a %b %d %H:%M:%S %Z %Y'') > date = d.to_s > year, month, day = date.split(/-/) > month = month.sub(/^0/,'''') > puts day + "/" + month + "/" + year > > puts d.strftime(''%a %b %d %H:%M:%S %Z %Y'') > > On May 8, 10:49 pm, aveo <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > Yes It worked, Many thanks. Can we change the format and display it in > > > > > dd-mm-yyyy format ? also can we do it reversely, > > > like "2006-11-20" date to "Mon Nov 20 00:00:00 UTC+0530 2006" ? > > > > Hi , > > I''ve tried it like, > > ################## > > t = ''Mon Nov 20 00:00:00 UTC+0530 2006'' > > d= Date.strptime(t, ''%a %b %d %H:%M:%S %Z %Y'') > > date = d.to_s > > year, month, day = date.split(/-/) > > month = month.sub(/^0/,'''') > > puts day + "/" + month + "/" + year > > ########################## > > ==> 20/11/2006 > > > > It is working. Can we convert it again to "Mon Nov 20 00:00:00 UTC+0530 > > 2006" ? > > :~} > > > > Regards, > > > > -- > > Posted viahttp://www.ruby-forum.com.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---