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" ) ) );