Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 358 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting only Month and Year from SQL DATE

#11
let's write it this way: `YEAR(anySqlDate)` and `MONTH(anySqlDate)`. Try it with `YEAR(GETDATE())` for example.
Reply

#12
My database doesn't support most of the functions above however I found that this works:

<code>SELECT * FROM table WHERE SUBSTR(datetime_column, starting_position, number_of_strings)=required_year_and_month;</code>

for example:
<code>SELECT SUBSTR(created, 1,7) FROM table;</code><br>

returns the year and month in the format "yyyy-mm"

Reply

#13
There are two SQL function to do it:

* [DATEPART()](

[To see links please register here]

)
* [YEAR()](

[To see links please register here]

) and [MONTH()](

[To see links please register here]

).

Refer to the linked documentation for details.
Reply

#14
SELECT convert(varchar(7), getdate(), 126)

You might wanna check out this website:

[To see links please register here]

Reply

#15
***Get Month & Year From Date***

DECLARE @lcMonth nvarchar(10)
DECLARE @lcYear nvarchar(10)

SET @lcYear=(SELECT DATEPART(YEAR,@Date))
SET @lcMonth=(SELECT DATEPART(MONTH,@Date))
Reply

#16
SELECT REPLACE(RIGHT(CONVERT(VARCHAR(11), GETDATE(), 106), 8), ' ', '-')

Output: Mar-2019
Reply

#17
Query :- `Select datename(m,GETDATE())+'-'+cast(datepart(yyyy,GETDATE()) as varchar) as FieldName`

Output :- January-2019

general datefield we can use

datename(m,<DateField>)+' '+cast(datepart(yyyy,<DateField>) as varchar) as FieldName

Reply

#18
For result: "YYYY-MM"

SELECT cast(YEAR(<DateColumn>) as varchar) + '-' + cast(Month(<DateColumn>) as varchar)
Reply

#19
select convert(varchar(11), transfer_date, 106)


got me my desired result of date formatted as 07 Mar 2018


My column 'transfer_date' is a datetime type column and I am using SQL Server 2017 on azure
Reply

#20
CONCAT (datepart (yy,DATE), FORMAT (DATE,'MM'))

gives you eg 201601 if you want a six digit result
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through