# Append a timestamp to file

**URL:** <https://www.ruby-forum.com/t/append-a-timestamp-to-file/136903>\
**Category:** Rails\
**Created:** [May 7, 2008, 9:43am UTC](https://www.ruby-forum.com/t/append-a-timestamp-to-file/136903 "2008-05-07T09:43:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [May 7, 2008, 9:43am UTC](https://www.ruby-forum.com/t/append-a-timestamp-to-file/136903/1 "2008-05-07T09:43:07Z")

</div>

im doing following code but it gives error  
temp=Time.now.to\_s  
file\_name = “#{temp}\_”+  
params[:group\_member\_information].original\_filename

so please reply how to append a timestamp to file name

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [May 7, 2008, 11:32am UTC](https://www.ruby-forum.com/t/append-a-timestamp-to-file/136903/2 "2008-05-07T11:32:57Z")

</div>

you could do something like that:

file\_name =  
“#{Time.now.to\_s}\_#{params[:group\_member\_information].original\_filename}”

but this would give you a time looking like  
Wed May 07 11:26:57 +0200 2008

so using  
Time.now.to\_s(:db)  
would look better

> but it gives error

what error?  
the code would be ok, if the params[:group\_member\_information] would be  
an uploaded file, what it most likely is not. so the error has most  
likely nothing to do with the Time or the filename you generate but with  
that param.
