How to add the current date to file name output?

   426   4   2
User Avatar
Member
269 posts
Joined: Aug. 2018
Offline
As far as I can see there is no built-in HScript variable for 'current date'. What would be the best option to add that to a ROP file name output on a Windows system?

I find it helpful to have a date + time variable when creating test renders.
User Avatar
Member
2 posts
Joined: Aug. 2015
Offline
I guess the easiest way is by python. Anyway you could find something useful in this topic [www.sidefx.com]
User Avatar
Member
2 posts
Joined: Jan. 2024
Offline
Hello my name is Sanjeev Mansotra from India.
To add the current date to a file name in a ROP file output on a Windows system, you can use Python expressions within Houdini since there’s no direct HScript variable for the current date. In the file name field, use this expression:

`pythonexprs("import datetime; datetime.datetime.now().strftime('%Y-%m-%d')")`

This will insert the current date in YYYY-MM-DD format, or adjust the date format within strftime() as needed. This approach is flexible and works well for dynamic date-stamping in output file names.
Edited by sanjeevmansotra - Oct. 29, 2024 07:43:15
User Avatar
Member
43 posts
Joined: Oct. 2021
Offline
Hi,
it seem to give a error..

Attachments:
Screenshot_21.jpg (132.8 KB)

Wow factor
User Avatar
Member
377 posts
Joined: April 2017
Offline
I posted a snippet in the linked thread that works, try this:

$HIP/render/$HIPNAME.$OS.`pythonexprs("str(__import__('datetime').datetime.now().strftime('%Y%m%d_%H%M%S'))")`.$F4.exr

Hscript doesn't seem to want to evaluate line breaks as Python sees them, so this is an alternative syntax you can use. If it's too ugly for you, create a spare string parm and set the expression to:

import datetime
return datetime.datetime.now().strftime('%Y%m%d_%H%M%S')

Then channel reference that in your filename expression using `chs("myParm")`
MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
  • Quick Links