<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Change Date format in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Change-Date-format/m-p/777567#M95896</link>
    <description>&lt;P&gt;There is an error as I cannot run this, can anyone help?&lt;/P&gt;&lt;P&gt;// Function to reformat dates to dd/mm/yyyy&lt;BR /&gt;colName = Column Dialog( "Select Date Column" );&lt;BR /&gt;reformatDateColumn = Function({dt, colName},&lt;BR /&gt;dt = Current DataTable();If( Column( dt, colName ) == Empty(),&lt;BR /&gt;Throw( "The selected column does not exist in the current data table." );&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;// Function to identify and reformat the date&lt;BR /&gt;formatDate = Function({date},&lt;BR /&gt;// Check for different date formats and convert to dd/mm/yyyy&lt;BR /&gt;If( Contains( date, "/" ),&lt;BR /&gt;// Check if date is in dd/mm/yyyy or mm/dd/yyyy format&lt;BR /&gt;If( Substr( date, 3, 1 ) == "/",&lt;BR /&gt;// Assume dd/mm/yyyy format&lt;BR /&gt;date,&lt;BR /&gt;// Assume mm/dd/yyyy format and convert to dd/mm/yyyy&lt;BR /&gt;Concat( Word( 2, date, "/" ), "/", Word( 1, date, "/" ), "/", Word( 3, date, "/" ) )&lt;BR /&gt;),&lt;BR /&gt;// Handle mmddyyyy, ddmmyyyy, yyyymmdd, or yyyyddmm format&lt;BR /&gt;If( Length( date ) == 8,&lt;BR /&gt;// Check if first two digits form a valid month or day&lt;BR /&gt;If( Num( Substr( date, 1, 2 ) ) &amp;gt; 12,&lt;BR /&gt;// Assume ddmmyyyy format&lt;BR /&gt;Concat( Substr( date, 1, 2 ), "/", Substr( date, 3, 2 ), "/", Substr( date, 5, 4 ) ),&lt;BR /&gt;// Assume mmddyyyy format and convert to dd/mm/yyyy&lt;BR /&gt;Concat( Substr( date, 3, 2 ), "/", Substr( date, 1, 2 ), "/", Substr( date, 5, 4 ) )&lt;BR /&gt;),&lt;BR /&gt;If( Length( date ) == 8,&lt;BR /&gt;If( Num( Substr( date, 1, 4 ) ) &amp;gt; 999, // Check if first 4 digits form a valid year&lt;BR /&gt;// Check if the next two digits form a valid month or day&lt;BR /&gt;If( Num( Substr( date, 5, 2 ) ) &amp;gt; 12,&lt;BR /&gt;// Assume yyyyddmm format&lt;BR /&gt;Concat( Substr( date, 7, 2 ), "/", Substr( date, 5, 2 ), "/", Substr( date, 1, 4 ) ),&lt;BR /&gt;// Assume yyyymmdd format and convert to dd/mm/yyyy&lt;BR /&gt;Concat( Substr( date, 7, 2 ), "/", Substr( date, 5, 2 ), "/", Substr( date, 1, 4 ) )&lt;BR /&gt;),&lt;BR /&gt;// If not a valid year or format, return the original date&lt;BR /&gt;date&lt;BR /&gt;),&lt;BR /&gt;// If the date length is not 8, return the original date (invalid format)&lt;BR /&gt;date&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;);&lt;BR /&gt;&lt;BR /&gt;//Create the UI with buttons to trigger the functions&lt;BR /&gt;New Window( "Data Processing Tools",&lt;BR /&gt;V List Box(&lt;BR /&gt;// Button to reformat date column&lt;BR /&gt;Button Box( "Reformat Date Column",&lt;BR /&gt;// Open a dialog to select the date column&lt;BR /&gt;colName = Column Dialog( "Select Date Column" );&lt;BR /&gt;&lt;BR /&gt;// Call the function to reformat the selected date column&lt;BR /&gt;reformatDateColumn( Current Data Table(), colName );&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;);&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jul 2024 03:31:11 GMT</pubDate>
    <dc:creator>DecileIbex201</dc:creator>
    <dc:date>2024-07-31T03:31:11Z</dc:date>
    <item>
      <title>Change Date format</title>
      <link>https://community.jmp.com/t5/Discussions/Change-Date-format/m-p/777567#M95896</link>
      <description>&lt;P&gt;There is an error as I cannot run this, can anyone help?&lt;/P&gt;&lt;P&gt;// Function to reformat dates to dd/mm/yyyy&lt;BR /&gt;colName = Column Dialog( "Select Date Column" );&lt;BR /&gt;reformatDateColumn = Function({dt, colName},&lt;BR /&gt;dt = Current DataTable();If( Column( dt, colName ) == Empty(),&lt;BR /&gt;Throw( "The selected column does not exist in the current data table." );&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;// Function to identify and reformat the date&lt;BR /&gt;formatDate = Function({date},&lt;BR /&gt;// Check for different date formats and convert to dd/mm/yyyy&lt;BR /&gt;If( Contains( date, "/" ),&lt;BR /&gt;// Check if date is in dd/mm/yyyy or mm/dd/yyyy format&lt;BR /&gt;If( Substr( date, 3, 1 ) == "/",&lt;BR /&gt;// Assume dd/mm/yyyy format&lt;BR /&gt;date,&lt;BR /&gt;// Assume mm/dd/yyyy format and convert to dd/mm/yyyy&lt;BR /&gt;Concat( Word( 2, date, "/" ), "/", Word( 1, date, "/" ), "/", Word( 3, date, "/" ) )&lt;BR /&gt;),&lt;BR /&gt;// Handle mmddyyyy, ddmmyyyy, yyyymmdd, or yyyyddmm format&lt;BR /&gt;If( Length( date ) == 8,&lt;BR /&gt;// Check if first two digits form a valid month or day&lt;BR /&gt;If( Num( Substr( date, 1, 2 ) ) &amp;gt; 12,&lt;BR /&gt;// Assume ddmmyyyy format&lt;BR /&gt;Concat( Substr( date, 1, 2 ), "/", Substr( date, 3, 2 ), "/", Substr( date, 5, 4 ) ),&lt;BR /&gt;// Assume mmddyyyy format and convert to dd/mm/yyyy&lt;BR /&gt;Concat( Substr( date, 3, 2 ), "/", Substr( date, 1, 2 ), "/", Substr( date, 5, 4 ) )&lt;BR /&gt;),&lt;BR /&gt;If( Length( date ) == 8,&lt;BR /&gt;If( Num( Substr( date, 1, 4 ) ) &amp;gt; 999, // Check if first 4 digits form a valid year&lt;BR /&gt;// Check if the next two digits form a valid month or day&lt;BR /&gt;If( Num( Substr( date, 5, 2 ) ) &amp;gt; 12,&lt;BR /&gt;// Assume yyyyddmm format&lt;BR /&gt;Concat( Substr( date, 7, 2 ), "/", Substr( date, 5, 2 ), "/", Substr( date, 1, 4 ) ),&lt;BR /&gt;// Assume yyyymmdd format and convert to dd/mm/yyyy&lt;BR /&gt;Concat( Substr( date, 7, 2 ), "/", Substr( date, 5, 2 ), "/", Substr( date, 1, 4 ) )&lt;BR /&gt;),&lt;BR /&gt;// If not a valid year or format, return the original date&lt;BR /&gt;date&lt;BR /&gt;),&lt;BR /&gt;// If the date length is not 8, return the original date (invalid format)&lt;BR /&gt;date&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;);&lt;BR /&gt;&lt;BR /&gt;//Create the UI with buttons to trigger the functions&lt;BR /&gt;New Window( "Data Processing Tools",&lt;BR /&gt;V List Box(&lt;BR /&gt;// Button to reformat date column&lt;BR /&gt;Button Box( "Reformat Date Column",&lt;BR /&gt;// Open a dialog to select the date column&lt;BR /&gt;colName = Column Dialog( "Select Date Column" );&lt;BR /&gt;&lt;BR /&gt;// Call the function to reformat the selected date column&lt;BR /&gt;reformatDateColumn( Current Data Table(), colName );&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;);&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2024 03:31:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Change-Date-format/m-p/777567#M95896</guid>
      <dc:creator>DecileIbex201</dc:creator>
      <dc:date>2024-07-31T03:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: Change Date format</title>
      <link>https://community.jmp.com/t5/Discussions/Change-Date-format/m-p/777578#M95897</link>
      <description>&lt;P&gt;Could you explain what you are trying to instead of just the code (code looks like LLM created)?&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2024 04:39:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Change-Date-format/m-p/777578#M95897</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-07-31T04:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: Change Date format</title>
      <link>https://community.jmp.com/t5/Discussions/Change-Date-format/m-p/777579#M95898</link>
      <description>&lt;P&gt;I assume you have a data table with a character column which looks like dates. And it can have mixed formats of dates? And you wish to have UI to convert those to numeric format? JMP's Format Pattern might be able to do this, but it would be helpful to have an example of the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the original script in a bit easier to read format (hopefully I didn't make any changes outside of formatting the script)&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;colName = Column Dialog("Select Date Column");

reformatDateColumn = Function({dt, colName},
	dt = Current Data Table();
	If(Column(dt, colName) == Empty(),
		Throw("The selected column does not exist in the current data table.")
	);
);

formatDate = Function({date},
	If(Contains(date, "/"),
		If(Substr(date, 3, 1) == "/",
			date, 
			// Assume mm/dd/yyyy format and convert to dd/mm/yyyy
			Concat(Word(2, date, "/"), "/", Word(1, date, "/"), "/", Word(3, date, "/"))
		)
	, 
		// Handle mmddyyyy, ddmmyyyy, yyyymmdd, or yyyyddmm format
		If(Length(date) == 8, 
			// Check if first two digits form a valid month or day
			If(Num(Substr(date, 1, 2)) &amp;gt; 12, 
				// Assume ddmmyyyy format
				Concat(Substr(date, 1, 2), "/", Substr(date, 3, 2), "/", Substr(date, 5, 4))
			, 
				// Assume mmddyyyy format and convert to dd/mm/yyyy
				Concat(Substr(date, 3, 2), "/", Substr(date, 1, 2), "/", Substr(date, 5, 4))
			)
		,
			If(Length(date) == 8,
				// Check if first 4 digits form a valid year
				If(Num(Substr(date, 1, 4)) &amp;gt; 999, 
					// Check if the next two digits form a valid month or day
					If(Num(Substr(date, 5, 2)) &amp;gt; 12, 
						// Assume yyyyddmm format
						Concat(Substr(date, 7, 2), "/", Substr(date, 5, 2), "/", Substr(date, 1, 4))
					, 
						// Assume yyyymmdd format and convert to dd/mm/yyyy
						Concat(Substr(date, 7, 2), "/", Substr(date, 5, 2), "/", Substr(date, 1, 4))
					)
				, 
					// If not a valid year or format, return the original date
					date
				)
			, 
				// If the date length is not 8, return the original date (invalid format)
				date
			)
		)
	)
);

New Window("Data Processing Tools",
	V List Box(
		Button Box("Reformat Date Column", 
			// Open a dialog to select the date column
			colName = Column Dialog("Select Date Column");
			reformatDateColumn(Current Data Table(), colName);
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;</description>
      <pubDate>Wed, 31 Jul 2024 04:51:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Change-Date-format/m-p/777579#M95898</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-07-31T04:51:40Z</dc:date>
    </item>
  </channel>
</rss>

