Hitachi Vantara Pentaho Community Forums
Results 1 to 10 of 10

Thread: Transformation: How to add the date in file name as an output Example FilenameMMDDYY

  1. #1
    Join Date
    Oct 2008
    Posts
    8

    Post Transformation: How to add the date in file name as an output Example FilenameMMDDYY

    Hi Everybody,

    I am trying to create the daily transformation work, so every day I want to add the date in the file name, the date formate must be (MMDDYY).

    I tried to run by the java script, but some time it is working some time not

    I'm never get the file name + todays date, while I 'm trying to run from command prompt.

    Please let me know how to solve this problem....

    Regards,
    Piyush

  2. #2
    Join Date
    Jul 2007
    Posts
    1,013

    Default

    Are you talking about some output file your transformation generates, or the log information?

    If it's the first, I believe all of the output to file steps have the option to add the date to the filename. It's just a matter of ticking the checkbox.

    Cheers!

  3. #3
    Join Date
    Apr 2008
    Posts
    4,683

    Default

    For input files, both the Text File Input and CSV Input accept a data stream, so if you are looking for input files, you can either use a "Get Files" step, or a Modified Javascript step to generate the filename (eg. a single row with a single field "Filename") and connect it to one of the input steps.

    For output files... See tdidomenico's response.

  4. #4
    Join Date
    Jul 2007
    Posts
    1,013

    Default

    Piyush, I'm going to reply to the PM here, so everyone can continue discussing this thread:

    Quote Originally Posted by piyush.gnit
    Hi Tdidomenico,

    I appreciate your quick responsce, but I dont want that formate after using that check option as an output of the file name I will get outputfile_20090429.txt, I don't need this formate, Please help me to get the transformation output file name as outputfile042909.txt

    Thanks
    Piyush
    The option I see here is to get the date via system variable, manipulate it in Javascript to create the filename you want and then use this variable as file name in the output step. Is this what you say you tried?

    Cheers!

  5. #5
    Join Date
    Apr 2008
    Posts
    4,683

    Default

    There's another checkbox: Specify Date Time Format
    And a field: Date Time Format

    Check the Checkbox, and enter MMddyy in the field.

    This will give you outputfile042909.txt

  6. #6
    Join Date
    Jul 2007
    Posts
    1,013

    Default

    Quite right! Much easier. Available on 3.1 and up (I need to upgrade, badly :P)

  7. #7
    Join Date
    Oct 2008
    Posts
    8

    Question

    I checked on 3.1 version, there is no option to chose the option to get the MMddyy date into output file name,

    Iam trying to solve this by using javascrip option, after transformation over rename the file, I think this a quite easier, but I'm not able to get output, the script showing error, Please can you help to get the correct output, it's better that if you will give me an example so that i can refer it.....

    General error executing script:
    ReferenceError: "CreateObject" is not defined. (script#30)


    Below is the code:
    var
    StrDate = new Date();

    StrDate1 = StrDate.getMonth()+ 1;
    StrDate2 = StrDate.getDate();
    StrDate3 = StrDate.getFullYear();

    StrDate1 = StrDate1.toString();
    StrDate2 = StrDate2.toString();
    StrDate3 = StrDate3.toString();

    // get the Month Formate (MM)
    if
    (StrDate1.length<2)
    {
    StrDate1 =
    "0" + StrDate1;
    }

    // get the Date Formate (DD)
    if
    (StrDate2.length<2)
    {
    StrDate2 =
    "0" + StrDate1;
    }

    // get the Year Formate (YY)
    StrDate3 =StrDate3.substring(2,4);

    TodayDateStamp=StrDate1 + StrDate2 +StrDate3;
    //Alert(TodayDateStamp);

    var fso = new CreateObject("Scripting.FileSystemObject");
    varFileObject = fso.CopyFile (
    "c:test.txt", "c:test${TODAYDATESTAMP}.txt");

    varFileObject.close();

  8. #8

    Default

    In version 3.1 if you are using a text file output, you should be able to specify a date time format. This is the easiest way to do it.

    If you want to do it in JavaScript then format the date:
    var
    dateval=date2str(systemdate.getDate(),"MMddyy")
    dateval is a string, you can then concatenate this to your filename.

  9. #9
    Join Date
    Feb 2009
    Posts
    296

    Default

    Quote Originally Posted by piyush.gnit View Post
    var fso = new CreateObject("Scripting.FileSystemObject");
    varFileObject = fso.CopyFile ("c:test.txt", "c:test${TODAYDATESTAMP}.txt");

    varFileObject.close();
    OMG - this is Windows Scripting. You're in a JavaScript step. You need to use JavaScript there.

    dondem5 gave you the answer but I couldn't resist...
    Fabian,
    doing ETL with his hands bound on his back

  10. #10
    Join Date
    Oct 2008
    Posts
    8

    Lightbulb

    can you tell me how to concatenate the data stamp (MMDDYY) in the file name, I am not able to do that, can you provide me example..


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.