cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
cchueng
Level IV

Changing char date column to numeric date

Hello,

Attached is a table with a column called StartDate. It is in char format and have excessive '0's at the end of each date. I wish to write a script to change the StartDate column to this format like : 04/12/2024 4:10:09 PM. Any help is appreciated.

 

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Changing char date column to numeric date

Here is a little script that will create a new numeric date/time column converting your StartTime column values.

Names Default To Here( 1 );
dt = Current Data Table();
dt << New Column( "StartTime2",
	set each value(
		Informat( Word( 1, :StartTime, "+" ), "yyy/mm/ddThh:mm:ss" )
	),
	Format( "m/d/y h:m:s" )
);

 

txnelson_0-1714191846052.png

 

Jim

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: Changing char date column to numeric date

Here is a little script that will create a new numeric date/time column converting your StartTime column values.

Names Default To Here( 1 );
dt = Current Data Table();
dt << New Column( "StartTime2",
	set each value(
		Informat( Word( 1, :StartTime, "+" ), "yyy/mm/ddThh:mm:ss" )
	),
	Format( "m/d/y h:m:s" )
);

 

txnelson_0-1714191846052.png

 

Jim
cchueng
Level IV

Re: Changing char date column to numeric date

Thank you, this works!

hogi
Level XIII

Re: Changing char date column to numeric date

I wondered about the "T" ...

Actually,

dt = Current Data Table();
dt << New Column( "StartTime2",
	set each value(
		Informat( Word( 1, :StartTime, "+" ), "hello" )
	),
	Format( "m/d/y h:m:s" )
);

does the job as well :)

It's the power of Informat: For most cases there is no need to specify the pattern, Informat will detect it on it's own.
https://community.jmp.com/t5/Discussions/Informat-ParseDate-function-with-time/m-p/736131/highlight/... 


Just for some rare cases (like DD.MM.YYYY ) you have to invest some additional effort.
Either specify the pattern via "Format Pattern", your pattern ,
or via Date Format Writer from the  Data Table Tools Add-in :
https://community.jmp.com/t5/JMP-On-Air/The-Doctor-Cures-Your-Date-and-Time-Import-Problems/tac-p/73... 
:)

hogi
Level XIII

Re: Changing char date column to numeric date

maybe the easiest way:
open the column properties, and change the data type to numeric, then specify the pattern.


a) row 13 shows:
with the pattern <ss> Jmp automatically reads the seconds including the digits after the point.

hogi_0-1714326583055.png

 

b) The only thing that is not automatically detected is the timezone offset *)
→ if all values are the same, you can just add " +00:00" - to get it "ignored".

*) Date Format Pattern - additional functionality 

 

(view in My Videos)

Recommended Articles