getdate

Changing the output of Getdate

萝らか妹 提交于 2019-11-27 07:38:26
问题 Is it possible to deceive SQL Server to return a different date on GetDate() without actually changing the machine date? This would be great, since we have a database with old data and I'm trying to test some queries that use getdate(). I can change my machine date but that brings some other problems with other applications... Any tips? Thanks! 回答1: According to the documentation for getdate(): This value is derived from the operating system of the computer on which the instance of SQL Server

Retrieving date in sql server, CURRENT_TIMESTAMP vs GetDate()

杀马特。学长 韩版系。学妹 提交于 2019-11-27 04:09:08
Using SQL Server - which is the fastest or best practice method to use for date retrieval? Is there a difference? CURRENT_TIMESTAMP is standard ANSI SQL, and so is theoretically one tiny little island of 'don't need to change' amongst your thousands of SQL Server-specific lines of SQL if you ever need to move databases.... CURRENT_TIMESTAMP is part of the ANSI SQL spec. GETDATE() is a SQL Server-specific function inherited from the original Sybase code on which SQL Server is based. They do exactly the same thing, though. My vote is for CURRENT_TIMESTAMP for 'portability' reasons i.e. why be

Incorrect syntax near ')' calling stored procedure with GETDATE

巧了我就是萌 提交于 2019-11-27 01:47:18
Maybe I am having a moment of 'afternoon', but can anyone explain why I get Msg 102, Level 15, State 1, Line 2 Incorrect syntax near ')'. When running CREATE PROC DisplayDate (@DateVar DATETIME) AS BEGIN SELECT @DateVar END GO EXEC DisplayDate GETDATE(); You can't pass in a function call as an argument to your stored procedure. Instead use an intermediate variable: DECLARE @tmp DATETIME SET @tmp = GETDATE() EXEC DisplayDate @tmp; As Mitch Wheat mentioned you can't pass a function. If in your case you should pass in a precalculated value or GETDATE() - you can use default value. For example,

JavaScript's getDate returns wrong date

佐手、 提交于 2019-11-26 20:04:57
The following script returns 20 instead of 21! var d = new Date("2010/03/21"); document.write(d.getDate()); What am I doing wrong? Is this a JavaScript bug? The Date.parse method is implementation dependent ( new Date(string) is equivalent to Date.parse(string) ). While this format will be available on modern browsers, you cannot be 100% sure that the browser will interpret exactly your desired format. I would recommend you to manipulate your string, and use the Date constructor with the year, month and day arguments: // parse a date in yyyy-mm-dd format function parseDate(input) { var parts =

JDBC ResultSet: I need a getDateTime, but there is only getDate and getTimeStamp

↘锁芯ラ 提交于 2019-11-26 19:48:48
问题 I would like to get the DATETIME column from an Oracle DB Table with JDBC. Here is my code: int columnType = rsmd.getColumnType(i); if(columnType == Types.DATE) { Date aDate = rs.getDate(i); valueToInsert = aDate.toString(); } else if(columnType == Types.TIMESTAMP) { Timestamp aTimeStamp = rs.getTimestamp(i); valueToInsert = aTimeStamp.toString(); } else { valueToInsert = rs.getString(i); } I have to identify the column type first. The field I am interested in is recognized as a Types.DATE,

Getting the date from a ResultSet for use with java.time classes

末鹿安然 提交于 2019-11-26 14:07:33
问题 Is there anyway to get a java.time (new in Java 8) compatible time class out of a ResultSet ? I am aware you can use ResultSet 's getDate or getTimestamp but these method return java.sql.Date / java.sql.Timestamp objects which are now deprecated so it seems like bad practice to use them in order to create a ZonedDateTime or similar. 回答1: Most database vendors don't support JDBC 4.2 yet. This specification says that the new java.time -types like LocalDate will/should be supported using the

Retrieving date in sql server, CURRENT_TIMESTAMP vs GetDate()

▼魔方 西西 提交于 2019-11-26 11:04:38
问题 Using SQL Server - which is the fastest or best practice method to use for date retrieval? Is there a difference? 回答1: CURRENT_TIMESTAMP is standard ANSI SQL, and so is theoretically one tiny little island of 'don't need to change' amongst your thousands of SQL Server-specific lines of SQL if you ever need to move databases.... 回答2: CURRENT_TIMESTAMP is part of the ANSI SQL spec. GETDATE() is a SQL Server-specific function inherited from the original Sybase code on which SQL Server is based.

Incorrect syntax near ')' calling stored procedure with GETDATE

☆樱花仙子☆ 提交于 2019-11-26 09:46:20
问题 Maybe I am having a moment of \'afternoon\', but can anyone explain why I get Msg 102, Level 15, State 1, Line 2 Incorrect syntax near \')\'. When running CREATE PROC DisplayDate (@DateVar DATETIME) AS BEGIN SELECT @DateVar END GO EXEC DisplayDate GETDATE(); 回答1: You can't pass in a function call as an argument to your stored procedure. Instead use an intermediate variable: DECLARE @tmp DATETIME SET @tmp = GETDATE() EXEC DisplayDate @tmp; 回答2: As Mitch Wheat mentioned you can't pass a