Date should be updated in Target file by calling power shell

Welcome Forums General PowerShell Q&A Date should be updated in Target file by calling power shell

Viewing 8 reply threads
  • Author
    Posts
    • #245691
      Inactive
      Topics: 2
      Replies: 7
      Points: 0
      Rank: Member

      Hi Team,

      I have a requirement where Source file has a date format as  m/d/yyyy or mm/d/yyyy or m/dd/yyyy or mm/dd/yyyy i have to get the output(Target) file with only one date format like ‘mm-dd-yyyy’ or ‘yyyy-mm-dd’

      Could you please help me with this?

      Thanks,

      Krish V

    • #245751
      Senior Moderator
      Topics: 10
      Replies: 161
      Points: 871
      Helping Hand
      Rank: Major Contributor

      1) What is the source of the input date? is it contained in a text file? a csv? excel sheet? pdf? What method are you using to bring that information into PowerShell?

      2) Are you familiar with regex at all?

      3) What format does the output date need to be in? Generally, in order to effectively work with information in PowerShell, it needs to be contained in an object. However, if you need to use the output with a different application, then you will probably want it to be something other than a PowerShell object (e.g. by writing it out to a text file or csv). How do you intend to use the result when you have it?

    • #245826
      Inactive
      Topics: 2
      Replies: 7
      Points: 0
      Rank: Member

      Hello,

      1. Source of input data is SQL server. Source team is not going to change the way how they send the dates. We are using TDM stored procedures to load  data to target. And the output file is a test file in a network shared drive.
      2. Had a idea on regex function but not extensively
      3.  Here is the input file data which loads to File load,

      H|MEMBER_ID|LAST_NAME|FIRST_NAME|DOB|STATUS|SUB_STATUS|REFERRED_DATE|REFERRAL_TYPE|INITIAL_DATE|LAST_ATTEMPT|OUT|FIRST_DATE|VISIT_DATE|LAST_DATE|SCHEDULED_DATE|VENDOR_NAME|PROGRAM_NAME|REPORT_FILE_NAME
      D|10002998|Dough|Mories|10/08/1947|Active|Plus|9/26/2018|ALGOR|9/28/2018|12/24/2018|N|9/28/2018|12/24/2018|12/24/2018|POWER|ABCD|ABCD_ENROLLMENT_202006142113.TXT

      We need to check the date format on each record and date field using powershell script and the date format of the output test file should be changed to ‘yyyy-mm-dd’

      Expected :

      H|MEMBER_ID|LAST_NAME|FIRST_NAME|DOB|STATUS|SUB_STATUS|REFERRED_DATE|REFERRAL_TYPE|INITIAL_DATE|LAST_ATTEMPT|OUT|FIRST_DATE|VISIT_DATE|LAST_DATE|SCHEDULED_DATE|VENDOR_NAME|PROGRAM_NAME|REPORT_FILE_NAME

      D|10002998|Dough|Mories|1947-07-27|Active|Plus|9/26/2018|ALGOR|2018-28-09|2018-24-12|N|2018-28-12|2018-24-12|2018-24-12|POWER|ABCD|ABCD_ENROLLMENT_202006142113.TXT

      Please let me know for any more questions.

      Thanks,

      Krish

    • #245883
      Participant
      Topics: 7
      Replies: 557
      Points: 2,122
      Helping Hand
      Rank: Community Hero

      Krish,
      This seems quite similar to your previous question https://powershell.org/forums/topic/split-name-and-date-part-using-powershell/
      This forum is to help you with your powershell code, not to write code for you. Please post very clear information regarding what you’re trying to accomplish, what you’ve tried, and any errors you’re receiving. Sample data is always useful for those that choose to help us. You can edit your post as well, you don’t have to create a new one.

    • #245955
      Inactive
      Topics: 2
      Replies: 7
      Points: 0
      Rank: Member

      Hi Dough,

      We have discussed on how to split the output file name. This is about the data inside the file. What i am trying to accomplish is to change the date format inside the target file. This another requirement. Both were different. Please share some idea. I will work on the rest.

      Thanks,

      Krish

    • #245958
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      What i am trying to accomplish is to change the date format inside the target file. This another requirement. Both were different. Please share some idea. I will work on the rest.

      Create a loop and use the existing dates to re-format them … something like this: Get-Date '10/08/1947' -Format 'yyyy-MM-dd'

    • #245961
      Participant
      Topics: 7
      Replies: 557
      Points: 2,122
      Helping Hand
      Rank: Community Hero

      Hi Krish,

      I apologize for not being clear enough. What I’m saying is, show us your attempts. You have addressed the forum as Team, asking for help achieving your goal.. but haven’t showed us what you’ve tried. I, at least personally, will assume that you haven’t tried anything based on your request. I’m simply asking you to put in at least the same amount of effort in figuring this out yourself that many of us are willing to put in helping you. What have you tried? Where is it going wrong?

      Hopefully this conveys the meaning of my words better.

    • #245970
      Participant
      Topics: 13
      Replies: 1753
      Points: 3,136
      Helping Hand
      Rank: Community Hero

      Hi Dough,

      Giggle. Henceforth, Krzy Doug shall be addressed as Dough

    • #245982
      Participant
      Topics: 7
      Replies: 557
      Points: 2,122
      Helping Hand
      Rank: Community Hero

      Giggle. Henceforth, Krzy Doug shall be addressed as Dough

      All my life.. by mistake and on purpose…

Viewing 8 reply threads
  • You must be logged in to reply to this topic.