cancel
Showing results for 
Search instead for 
Did you mean: 

How do I remove a datetime stamp from a text file?

kimmatsumoto
Contributor

How do I remove a datetime stamp from a text file?

How do I remove the datetime stamp from the following text file?

 

"SYSDBA","05/17/2017 1:09:40 PM","Update","","BRANCH","1","0"

 

 

Thanks,

Kim

10 REPLIES 10
Marsha_R
Community Hero

Re: How do I remove a datetime stamp from a text file?

NisHera
Valued Contributor

Re: How do I remove a datetime stamp from a text file?

Hi,

This would be much complicated.

you have to read entire file to a string variable , select date format in this variable using Regex.

Then re write the file.

But if you tell us what you are trying to achieve (the context of your problem ) there may be more simple solutions.

shankar_r
Community Hero

Re: How do I remove a datetime stamp from a text file?

Hi,

 

you can use below function to phrase your text input, there couple of ways to remove the date and time.

 

1. As

 

 

function convertTime()
{
      var sampleString = aqFile.ReadWholeTextFile("D:\\CommunityDay\\sample.txt",20);
      
      
      aqString.ListSeparator = ","; 
           
      if(sampleString != "")
      {
            for(var i = 0 ; i < aqString.GetListLength(sampleString) ; i++)
            {
                  //if(Rgular expression match for date format)
                  //{
                   Log.Message(aqString.GetListItem(sampleString,i));
                  //} 
            }
      } 
      
} 

Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

tristaanogre
Community Hero

Re: How do I remove a datetime stamp from a text file?

Considering the file is formatted much like a CSV, you could use DDT.CSVDriver to read out the values of the file and then rewrite them to a new file, making sure that, when you write the date column that you just leave it blank.

 

You could use aqFile.OpenTextFile to open the file and then, in a while loop on EOF, read each line, use aqString.GetListItem as mentioned before to parse out the date, and then re-write the file.  

 

Any one of these methods would work just as well as any other.  Personally, I don't like regular expressions so, since the file has a structure that allows it, the GetListItem or CSV method would be my preferred ways.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
kimmatsumoto
Contributor

Re: How do I remove a datetime stamp from a text file?

Hi...thanks to everyone for their help.  It was suggested that I include what I'm trying to achieve...

I'm writing the contents of a grid to a text file (notepad) which will be used as a baseline during a file compare. The problem is the file includes a datetime stamp which will cause the file comparison to always fail.  

 

The notepad file looks like this: "SYSDBA","05/17/2017 1:09:40 PM","Update","","BRANCH","1","0"

My goal is to end up with a file looking like one of the following:

"Update","","BRANCH","1","0"

"SYSDBA","Update","","BRANCH","1","0"

 

This is a copy of the code I'm using:

procedure Test;
var
  tempFileName4, FileName4, str : OleVariant;
begin
  tempFileName4 := Project.Path + '4199_4_temp.txt';

 //Save 2nd row in listview to file
 listview := TBO.HistoryForm.CDSListView1;
 ListViewItemToCSVFile4(listview, tempFileName4, 1);
 //Verify 2nd item displays: BRANCH (field), 1 (Old Value), 0 (New Value)
 if Files.Compare(FileName4, tempFileName4) then
  log.Checkpoint(tempFileName4+' matches baseline.');

end;

 

Thanks in advanced,

Kim

shankar_r
Community Hero

Re: How do I remove a datetime stamp from a text file?

Hi,

 

ListViewItemtoCSVFile4 is writing output value to a tempFilename4

 

Then you are comparing tempFileName4 with FileName4.

 

If my understanding is correct,

 

FileName4 will have the contents with Timestamp and tempFileName4 will not have the timestamp

 

So, Checkpoint going fail in this scenario.

 

Correct me if my understanding is wrong

 


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

tristaanogre
Community Hero

Re: How do I remove a datetime stamp from a text file?

If ListViewItem4 is under your control, your answer is there.  When you're reading the listView and writing it to the file, detect when a field contains a date (use aqString.StrMatches and use a regular expression).  If the field contains a date, write out a blank, otherwise, write out the actual value.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
kimmatsumoto
Contributor

Re: How do I remove a datetime stamp from a text file?

Yes, ListViewItemToCSVFile4 is writing output (in text format) to the file tempFileName4 which gets compared to the baseline file (FileName4).
The file tempFileName4 will have the timestamp which I want to remove and save and then compare it against FileName4 (baseline) which will not have a timestamp.
FYI...to get the baseline file I copied tempFileName4 and renamed to FileName4 and then manually deleted the timestamp.

tristaanogre
Community Hero

Re: How do I remove a datetime stamp from a text file?


@kimmatsumoto wrote:

Yes, ListViewItemToCSVFile4 is writing output (in text format) to the file tempFileName4 which gets compared to the baseline file (FileName4).
The file tempFileName4 will have the timestamp which I want to remove and save and then compare it against FileName4 (baseline) which will not have a timestamp.
FYI...to get the baseline file I copied tempFileName4 and renamed to FileName4 and then manually deleted the timestamp.


Exactly... so... edit ListViewItemToCSVFile4 to filter out the datetime stamp in it's writing to your temp filename.  Again, detection can be used with aqString.StrMatches and then just write out the line to your file without the date time stamp.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
New Here?
Join us and watch the welcome video:
Announcements