Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
declare @Date1 Datetime, @Date2 DateTime 
set @Date1 = '2016/1/1 00:00:00' 
set @Date2 = @Date1 +  DATEDIFF(d,'2016/1/1 00:00:00', '2016/1/31 23:59:59' )
SELECT Day(Date) AS DDate,Month(Date) AS MDate,Year(Date) as YDate
FROM dbo.DateBackbone( @Date1,  @Date2)


What I have tried:

I have not found using DateBackBone function in MySql query it is work in MS_Sql Server query!
Posted
Comments
_Asif_ 9-Feb-16 4:26am    
DateBackbone is not part of MSSQL Server, its a user defined function. Share this UDF code of this function and what have you tried by the way?
Wathon Aung 9-Feb-16 4:38am    
I have not this UDF I only use DateBackbone(Date1,Date2). DateBackBone is not implement in my MSSql Server.
_Asif_ 9-Feb-16 4:45am    
Try responding following queries :|
* This SQL Code is running fine on MS SQL Server?
* If yes then can you share DateBackBone(Date1, Date2) code here? you can view this code by executing below query in SQL Window
sp_helptext 'dbo.DateBackbone'
Wathon Aung 9-Feb-16 23:08pm    
Yeah I got this function dbo.DateBackbone from my Ms Sql Server, but how can I change this function for usinng in my Mysql database with phpMyAdmin?

CREATE FUNCTION [dbo].[DateBackbone](@StartDate Datetime,@EndDate DateTime)

RETURNS @Dates TABLE (Date DateTime) AS

BEGIN
While @StartDate <= @EndDate
BEGIN
insert @Dates (Date) Values (@StartDate)
Set @StartDate = @StartDate + 1
END
RETURN

END

1 solution

There no such function as DateBackBone in either SQL Server or MySQL.

I can only presume you are referring the function found at this post - How to select all the dates of month even though there are no records? - qtoue[^]. Either you or someone with access to your system has already created the function (UDF).

The function works fine on MSSQL - it may be the format of your dates that is causing the problem. You could try using '-' instead of '/' .

If you are actually just trying to generate the list of dates in the month then try the following instead (which you could put in a function)
SQL
declare @Date1 Datetime = '2016-1-1 00:00:00' 
declare @Date2 DateTime = @Date1 +  DATEDIFF(d,'2016-1-1 00:00:00', '2016-1-31 23:59:59' )
;WITH q AS
    (
    SELECT   @Date1 AS datum
    UNION ALL
    SELECT  datum + 1
    FROM    q
    WHERE datum + 1 <= @Date2
    )
SELECT Day(datum) AS DDate,Month(datum) AS MDate,Year(datum) as YDate
FROM    q

which I took from Generating a Sequence in SQL[^] (Disclaimer: I am credited with co-authorship of that article, but this work is from @ManasBhardwaj)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900