如何使用脚本任务创建 Employee_YYYYMMDDHHMMSS.txt 格式的文本文件,并且每次我们运行该任务时,秒数都应该增加
user2216997
问问题
7157 次
2 回答
3
string Filename = "Employee_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
StreamWriter Writer = new StreamWriter(Filename);
Writer.WriteLine("Line");
Writer.Close();
于 2013-03-27T18:47:15.523 回答
0
在 C# 中,您可以像这样构建该字符串:
var fileName = string.Format("Employee_{0}.txt",
DateTime.Now.ToString("yyyyMMddHHmmss"));
在 T-SQL 中,您可以通过以下方式获取该字符串:
SELECT 'Employee_'
+ CAST(DATEPART(year, GETDATE()) AS VARCHAR(4))
+ RIGHT('0' + CAST(DATEPART(month, GETDATE()) AS VARCHAR(4)), 2)
+ RIGHT('0' + CAST(DATEPART(day, GETDATE()) AS VARCHAR(4)), 2)
+ RIGHT('0' + CAST(DATEPART(hour, GETDATE()) AS VARCHAR(4)), 2)
+ RIGHT('0' + CAST(DATEPART(minute, GETDATE()) AS VARCHAR(4)), 2)
+ RIGHT('0' + CAST(DATEPART(second, GETDATE()) AS VARCHAR(4)), 2)
+ '.txt'
于 2013-03-27T18:50:10.330 回答