VBScript or RegEx a date stamp

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

VBScript or RegEx a date stamp

Post by JRL » Wed Nov 04, 2009 8:04 pm

Can anybody accomplish more or less this same thing using a one line RegEx?

Code: Select all

VBSTART
VBEND
VBEval>replace((replace((replace((now),"/","")),":",""))," ",""),~date~stamp~

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed Nov 04, 2009 11:36 pm

It looks like you are removing the "\" and the ":" and all spaces?
How many digits in the year, leading "0" on days/months? Including time as well as date?

Examples with dates only?:
Changing from 2009/11/4 to 2009114
Changing from 2009/11/04 to 20091104
Changing from 2009/6/14 to 2009614
Changing from 2009/06/14 to 20090614
Changing from 11/4/2009 to 1142009
Changing from 11/4/2009 to 11409 or 110409 or 11042009

Some questions:
Since you are using "NOW", the format will actually be the system format, and may be different on each system.
1. If using time should result be in source format or 12/24 hour format?
2. Is it OK to get the current date/time with Macro Scheduler commands, or must we use "NOW"?
3. Do you need to have this work with all system formats as a source, and what format do you want in the end?

Please show the BEFORE and AFTER date strings....
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Nov 05, 2009 12:35 am

Hi Bob,

I'm just looking for a text "uniquifier" to append to file names. In the past I've always used :

Code: Select all

Month>mm
Day>dd
Year>yy
Hour>hh
Min>mn
Sec>ss

Let>timestamp=%mm%%dd%%yy%%hh%%mn%%ss%
I was just looking for a way to shorten the process

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu Nov 05, 2009 3:20 am

You have done that with your "timestamp" routine.
Let>Filename=basename_%timestamp%.ext

I would suggest that you use YYMMDD vs MMYYDD in order get sorting capability that will be chronological.
-------------------------------------------

Here is a RegEx solution:

Code: Select all

DateStamp>c:\temp\mylogfile.txt,
ReadFile>c:\temp\mylogfile.txt,vHaystack
DeleteFile>c:\temp\mylogfile.txt
RegEx>([0-9]{4})-([0-9]{2})-([0-9]{2}):([0-9]{2}):([0-9]{2}):([0-9]{2}):([0-9]{3}).*,%vHaystack%,0,vMatch,vMatchCount,1,$1$2$3$4$5$6$7,vNewString
Message>File name appendage = %vNewString%
The RegEx Pattern could be modified to be more specific in the range of numbers:
(20[0-9]{2})-([0-1][0-9])-([0-3][0-9]):([0-2][0-9]):([0-5][0-9]):([0-5][0-9]):([0-9]{3}).* . . . (Only good thru 2099)

It could also be modified by replacing everything inside parenthesis with ".*" (without the quotes):
(.*)-(.*)-(.*):(.*):(.*):(.*):(.*).*

Note, that both of the lines above are untested, just edited them here.

--------------------
You could also concatenate some MidStrings against vHaystack.
Many ways to do this, but I suspect you are just trying to better understand RegEx?
Last edited by Bob Hansen on Thu Nov 05, 2009 4:41 am, edited 7 times in total.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Post by gdyvig » Thu Nov 05, 2009 3:54 am

If you just want a unique number and don't need the actual date, you could use the vbscript datediff function:

This will return the number of seconds since the beginning of time, whatever you set that to.

Code: Select all

VBStart
VBEND
Let>BeginningOfTime=11/01/2009
VBEval>DateDiff("s","%BeginningOfTime%",NOW),secdiff
messagemodal>Difference Between NOW and BeginningOfTime= %secdiff% seconds

Gale

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts