Questions tagged [getdate]

getdate is a T-SQL function available to retrieve the current system date and time.

getdate() is a function that returns the current system date and time in a datetime format in RDBMSs that use T-SQL. It is available for use in MS SQL Server, SAP/Sybase Adaptive Server Anywhere, SAP/Sybase SQL Anywhere and SAP/Sybase IQ.

412 questions
158
votes
3 answers

Incorrect syntax near ')' calling stored procedure with GETDATE

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…
Nat
  • 14,175
  • 5
  • 41
  • 64
123
votes
7 answers

How to print GETDATE() in SQL Server with milliseconds in time?

I want to print GETDATE() in SQL Server 2008, I need the time with milliseconds (this is for debugging purpose - to find sp's execution time ) I find this Difference SELECT GETDATE() returns 2011-03-15 18:43:44.100 print GETDATE() returns Mar 15…
Ramakrishnan
  • 5,254
  • 9
  • 34
  • 41
99
votes
11 answers

Rounding SQL DateTime to midnight

I am having a small problem with my SQL query. I'm using the GETDATE function, however, let's say I execute the script at 5PM, it will pull up records between 12/12/2011 5PM to 12/18/2011 5PM. How can I make it pull up records for the whole entire…
henryaaron
  • 6,042
  • 20
  • 61
  • 80
75
votes
4 answers

Retrieving the date in SQL Server; CURRENT_TIMESTAMP vs GetDate()

Using SQL Server, which is the fastest or best practice method to use for date retrieval? Is there a difference between CURRENT_TIMESTAMP and GetDate()?
digiguru
  • 12,724
  • 20
  • 61
  • 87
56
votes
12 answers

JavaScript's getDate returns wrong date

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?
VahidN
  • 18,457
  • 8
  • 73
  • 117
54
votes
4 answers

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

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…
Tim
  • 3,910
  • 8
  • 45
  • 80
35
votes
3 answers

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

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…
Thomas Paulin
  • 515
  • 1
  • 6
  • 12
33
votes
2 answers

How to get a Date from a JSON object

I have a JSON object, which have one field that is a birthdate: JSONObject obj = new JSONObject(response); User user = new…
user2144555
  • 1,315
  • 11
  • 34
  • 55
26
votes
5 answers

How to compare only date part when delivery date is today

I'm trying to create a report that gets records from a SQL Server database where the delivery date is today. I've tried select * from (tablename) where delivery_date = getdate() Although that didn't give me any errors, it didn't give me any records…
user1777929
  • 777
  • 1
  • 10
  • 28
25
votes
6 answers

SSIS expression: convert date to string

I'm new to SSIS and I'm trying to convert a GetDate() to string "DD-MM-YYYY". This is the expression I've built so far: (DT_WSTR, 8) DAY( GETDATE()) + "-" + (DT_WSTR, 8) (MONTH(GETDATE()) - 1) + "-" + (DT_WSTR, 8) YEAR(GETDATE()) The problem…
resolver101
  • 2,155
  • 11
  • 41
  • 53
20
votes
11 answers

Convert getdate() to EST

I would like to convert getdate() in SQL Server to EST time.
derin
  • 201
  • 1
  • 2
  • 3
17
votes
4 answers

Selecting GETDATE() function twice in a select list-- same value for both?

I have a SELECT statement that uses GETDATE() for two different column values. I'm wondering if by the nature of things those two separate function calls in the same SELECT will return identical values every time?
larryq
  • 15,713
  • 38
  • 121
  • 190
17
votes
1 answer

How to add Leading Zero with getMonth in Java (Android)

I'm using an int variable: month = dp.getMonth() + 1; currently getting an output of "2" and when I do the following: if (month<10){ month = '0'+month; }; I get: 50.
Robby
  • 173
  • 1
  • 1
  • 4
17
votes
1 answer

SQL - Select records for the same day between particular data range

I need to check the SQL date range between some values. Example. To check records added between last 2 to 1 hours. Is the below query correct: SELECT * FROM tablename WHERE dtdatetime BETWEEN DATEADD(hh, -1, GETDATE()) AND DATEADD(hh, -2,…
Jay
  • 2,107
  • 4
  • 20
  • 24
16
votes
7 answers

how to format getdate into YYYYMMDDHHmmSS

In SQL Server how do I format getdate() output into YYYYMMDDHHmmSS where HH is 24 hour format? I've got the YYYYMMDD done with select CONVERT(varchar,GETDATE(),112) but that is as far as I got. Thanks.
Wayne
  • 914
  • 2
  • 13
  • 25
1
2 3
27 28