Normal Topic Mass Update - Date Format (Read 1035 times)
Vegas
Member
*
Offline



Posts: 2
Joined: Mar 16th, 2015
Mass Update - Date Format
Apr 30th, 2015 at 10:04pm
Print Post Print Post  
I'm trying to do a mass update to all dates across the database that are now entered as (i.e. 3-1-14, 3-1-2014) I need to change them to (3/1/2014). Has anyone had experience with this type of programming? I am not a programmer by any means any help would be appreciated.  Smiley
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2483
Joined: Aug 20th, 2003
Re: Mass Update - Date Format
Reply #1 - May 1st, 2015 at 2:10pm
Print Post Print Post  
Hello,

Is the element holding the value bound to a date field or is it bound to a string field?

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Vegas
Member
*
Offline



Posts: 2
Joined: Mar 16th, 2015
Re: Mass Update - Date Format
Reply #2 - Jul 23rd, 2015 at 5:22pm
Print Post Print Post  
Ray,

Some are bound to a date and some are bound to text. Not sure how to see if they are bound to string.
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2483
Joined: Aug 20th, 2003
Re: Mass Update - Date Format
Reply #3 - Jul 23rd, 2015 at 7:18pm
Print Post Print Post  
Hello Vegas,

String and Text are the same thing really. Text fields hold strings. I apologize if I confused you.

For the ones bound to date, you simple need to change the display format in Sesame Designer.

For the ones that are bound to text, if all that is ever stored in that element is a date then I would recommend changing the field type to Date. If the date is mixed in with other data, You'll need a Mass Update like the following:

Code
Select All
Var vData as String
Var vDatePositions as String
Var vLoop as Int
Var vCnt as Int
Var vDate as Array[3] of String
Var vWhich as Int
Var vStart as Int
Var vPos as Int
Var vLength as Int
Var vOffset as Int
Var vOldDateSep as Char
Var vNewDateSep as Char


//Pull element value into a string for easy manipulation
vData = ElementName

vOldDateSep = "-"
vNewDateSep = "/"

//Search for dates that have 1 or 2 digits then a dash then 1 or 2 digits then a dash and then 2 or 4 digits
vDatePositions = @RegexFindString(vData, "\d{1,2}" + vOldDateSep + "\d{1,2}" + vOldDateSep + "\d{2,4}", 1)
If vDatePositions <> "" Then
{
	vLoop = 1
	vOffset = 0
	vCnt = @CountStringArray(vDatePositions)
	While vLoop <= vCnt
	{
		//Loop through each date found in the data
		vWhich = 1
		vDate[1] = ""
		vDate[2] = ""
		vDate[3] = ""
		//Get the start position and the length of the Date found.
		vStart = @TN(@AccessStringArray(vDatePositions, vLoop)) + vOffset
		vLength = @AccessStringArray(vDatePositions, vLoop + 1)
		vPos = vStart
		While vPos < (vStart + vLength)
		{
			//Loop through the Date found character by character and place it into the array depending on how many dashes we have encountered.
			If @Mid(vData, vPos, 1) = vOldDateSep  Then
			{
				vWhich = vWhich + 1
			}
			Else
			{
				vDate[vWhich] = vDate[vWhich] + @Mid(vData, vPos, 1)
			}
			vPos = vPos + 1
		}
		//If it's a 2 digit year
		If @Len(vDate[3]) = 2 Then
		{
			vOffset = vOffset + 2
			//The next bit of code guesses that if the year is a two digit year that is greater than 15 that you mean 1900's
			If @TN(vDate[3]) > 15 Then
			{
				vDate[3] = "19" + vDate[3]
			}
			Else
			{
				vDate[3] = "20" + vDate[3]
			}
		}
		vData = @Left(vData, vStart-1) + vDate[1] + vNewDateSep + vDate[2] + vNewDateSep + vDate[3] + @Right(vData, @Len(vData)-(vStart + vLength)+1)
		//Advance by 2 to skip to the next occurence of a date
		vLoop = vLoop + 2
	}
}

//Set value back to the element
ElementName = vData 



I highly recommend making a backup before attempting this or any Mass Update. You'll need to replace ElementName with the name of the element you want to process.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged