Short Date() 创建锁定字符列当我在下面的脚本中创建一个“日期”列时,它会创建一个锁定的(因此我无法更改格式)列。公式中的 Short Date() 看起来是问题所在。
应用公式后,时间列保持为数字。
如何让“日期”保持数字?
日期稍后在 calender() 中设置日历以仅显示存在数据的日期。
___________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
//Open
dt_run = Open( "data.jmp");
dt_run << New Column( "Date", Numeric, Continuous, Format("m/d/y"), Input Format( "m/d/y h:m:s"));
Column( "Date") << Add Column Properties( Formula( Short Date( :Name( "Date & Time" ) ) ) );
dt_run << New Column( "Time", Numeric, Continuous, Format("h:m"), Input Format( "m/d/y h:m:s"));
Column( "Time") << Add Column Properties( Formula( Time Of Day( :Name( "Date & Time" ) ) ) );谢谢
马特
Re: Short Date() 创建锁定字符列您也可以通过将日期时间从秒更改为天和地板来仅使用数字来完成此操作。
Names Default to Here( 1 );
dt = New Table( "Test",
Add Rows( 1 ),
New Column( "DateTime",
Numeric,
"Continuous",
Format( "m/d/y h:m:s", 23, 0 ),
Formula( Today() ),
)
);
dt << New Column("Date",
Numeric,
"Continuous",
Format( "m/d/y", 23 ),
Formula(
num_s_per_day = 24*60*60; // # seconds/day
Floor(
:DateTime // take the date time which is a number in seconds
/ num_s_per_day // turn it into days by dividing
) // this will round down to the day
* num_s_per_day // turn it back into seconds (a date time)
),
);
Re: Short Date() 创建锁定字符列考虑一下你的 JSL ......你可以使用以下内容来填充你的 Date 列
Column( "Date") << set Formula( informat(Short Date( :Name( "Date & Time" ) ), "mm/dd/yyyy") );
它仅使用 Informat() 函数,该函数采用文字字符串并返回数字 JMP 日期值
Re: Short Date() 创建锁定字符列吉姆,
感谢您提供如此详尽的解释。 您的帖子总是内容丰富、有教育意义且易于理解。
马特Re: Short Date() 创建锁定字符列您遇到的问题与理解 Short Date() 函数返回的内容有关。它不返回 JMP 日期值,即自 1904 年 1 月 1 日凌晨 12:00 以来的秒数,而是返回 JMP 日期值的日期部分的文字字符串。为了说明这一点,以下 JSL 显示了 Short Date() 返回的内容:
show(short date(today())); <BR />
它返回
Short Date(Today()) = "12/03/2019";
由于在您的 JSL 中它返回了一个文字字符串,因此它将 Date 列更改为字符列。
实际上,您想要的是使用 DateMDY() 函数来创建日期值。
以下是您的代码的修改版本,它可以满足您的需求:
Names default to here(1);
dt_run = new table("data",add rows(1), new column("Date & Time",formula(today()),format("m/d/y h:m:s")));
dt_run << New Column( "Date", Numeric, Continuous, Format("m/d/y"));
Column( "Date") << set Formula( DateMDY(Month(:Name( "Date & Time" )),Day(:Name( "Date & Time" )),Year(:Name( "Date & Time" )) ) );
dt_run << New Column( "Time", Numeric, Continuous, Format("h:m"));
Column( "Time") << set Formula( Time Of Day( :Name( "Date & Time" ) ) );