Questions tagged [datepart]

DATEPART is a T-SQL function that converts a DATE type to INT according to provided format.

datepart(datepart,date_time_value) is a T-SQL function available in MS SQL Server and the SAP/Sybase family of database products.

SQL Server Syntax

SAP/Sybase Syntax

257 questions
22
votes
5 answers

Oracle equivalent to SQL Server DATEPART

We need to get the HOUR out of a DATETIME column (expecting values from 0 to 23 to be returned). Is there an Oracle equivalent of the SQL Server DATEPART function?
Raj More
  • 47,048
  • 33
  • 131
  • 198
16
votes
4 answers

SELECT row by DATEPART()

I need to get rows from the database where the records are of one month. I tried this SELECT: $result = mysql_query("SELECT * FROM my_table WHERE DATEPART('month', date_column)=11"); In database is a lot of rows that have a date in the 11. month,…
user1827257
  • 1,600
  • 4
  • 17
  • 24
13
votes
2 answers

Postgres Time Difference

I am trying to retrieve time difference in minutes from a table(login_history as t1) using postgresql . When i tried this code ((date_part('hour', timestamp '2014-04-25 09:44:21')- date_part('hour', timestamp '2014-04-25 08:32:21'))*60…
Md Rashedul Hoque Bhuiyan
  • 10,151
  • 5
  • 30
  • 42
12
votes
5 answers

How to compare two DATE values based only on date part in Oracle?

I am trying to get counts for last 30 days with the following query - SELECT date_occured, COUNT(*) FROM problem WHERE date_occured >= (CURRENT_DATE - 30) GROUP BY date_occured; //date_occured field is of type DATE. Basically, in my query I am…
Bhesh Gurung
  • 50,430
  • 22
  • 93
  • 142
10
votes
1 answer

How can I get the day of the week for a given date in PostgreSQL?

I want to retrieve day of the week from the given date. For example the date is: 2015-01-28 then it has to return Wednesday My bad try: select date_part('week',now()) as weekday; The above script gives me only number of week but not the day of the…
MAK
  • 6,824
  • 25
  • 74
  • 131
7
votes
4 answers

How do you convert the number you get from datepart to the name of the day?

Is there a quick one-liner to call datepart in Sql Server and get back the name of the day instead of just the number? select datepart(dw, getdate()); This will return 1-7, with Sunday being 1. I would like 'Sunday' instead of 1.
Eric Z Beard
  • 37,669
  • 27
  • 100
  • 145
4
votes
3 answers

Why is DATENAME(GETDATE()) giving a different result as DATENAME(2019-02-01) when that is the date today?

I don't understand why DATENAME(GETDATE()) gives a different result from DATENAME(2019-02-01) When that is today's date SELECT GETDATE(), DATENAME(w, GETDATE()),DATENAME(dw, 2019-02-01) Returns: 2019-02-01 14:51:46.017 Friday Monday
While I…
Vincentgsn
  • 53
  • 5
4
votes
4 answers

How to get year of character hijri date SQL Server

I searched and tried many examples unable to solve my hijri date is like, 19/07/1440 I tried this query SELECT TOP 200 DATEPART(YEAR, EndDateHejri) FROM student but I'm getting this error Conversion failed when converting date…
4
votes
2 answers

Epi-week query/method for SQL Server

The definition for epi-week is the following: "The first epi week of the year ends, by definition, on the first Saturday of January, as long as it falls at least four days into the month. Each epi week begins on a Sunday and ends on a…
OmGanesh
  • 952
  • 1
  • 12
  • 24
4
votes
3 answers

Extract weekday, millisecond, microsecond, nanosecond from a date in Postgres

How to extract the millisecond, weekday, microsecond, nanosecond from a date in Postgres. I have tried the extract methods too, but I could not find an exact equivalent.
Priya
  • 1,096
  • 4
  • 15
  • 32
4
votes
1 answer

Time difference between dateTime fields SSRS

I have two datetime fields and I need to show the difference between them. I've used this expression to calculate it: =DateDiff("n", Fields!hra_atncion.Value, Fields!fcha_incio.Value) The result column should be on HH:mm, but the result is a Long…
joisman
  • 89
  • 2
  • 10
4
votes
2 answers

Sybase Advantage Database Server and DATEPART

I'm looking to query a Sybase Advantage Database Server using DATEPART. I get an error message that states the following "Scalar function not found: datepart". Is there another function that has similar functionality? I'm looking get a date's…
3
votes
2 answers

How do i alter the code below to pad the minute and seconds with a 0 when it is a single digit?

The code below is doing just what i want it to do, as far as converting the time to a format that works for my needs. However, when the minutes and seconds are in the single digit, the format is not looking good. I would like to adjust the code to…
John
  • 475
  • 1
  • 12
  • 23
3
votes
2 answers

SQL Datepart - Starting the week on Monday instead of Sunday

I have run across an issue in a query using datepart. We have been using the following query to return the last three weeks of data, however we recently found out that corporate is using a reporting week from Monday-Sunday, while the below query is…
user852062
  • 55
  • 1
  • 5
3
votes
4 answers

Unique rows per day

I need to get a list of users email addresses that logged into my website over the course of a day. The list may contain duplicate email addresses but not more than one per day. I need to obtain this data for a week. I have a table that contains…
carrot_programmer_3
  • 915
  • 3
  • 14
  • 28
1
2 3
17 18