qns about Date field

KubirSingh 21 Reputation points
2020-10-09T10:30:52.313+00:00

Hi,
There is a Debit card expirationdate column in a field. In a storedProc, something like

Cast(Convert(varchar, DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,sExpirationDate)+1,0)),101) + ' 12:00pm' as DateTime)
&
Cast(Convert(varchar, DateAdd(Day,-1,c.sally_ExpirationDate),101) + ' 12:00pm' as DateTime)

is used.

I am not what are these two means? can you please help me on this?

Microsoft Q&A
Microsoft Q&A
Use this tag to share suggestions, feature requests, and bugs with the Microsoft Q&A team. The Microsoft Q&A team will evaluate your feedback on a regular basis and provide updates along the way.
821 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vaibhav Chaudhari 38,746 Reputation points
    2020-10-09T11:42:23.787+00:00

    Can you provide the sample values for sExpirationDate and c.sally_ExpirationDate?

    I assumed the dates as - 2020-08-15

    First query returns the the last day of that Month and second gives the previous da

    select Cast(Convert(varchar, DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,'2020-08-15')+1,0)),101) + ' 12:00pm' as DateTime)
    -- Output - 2020-08-31 12:00:00.000 - Last day of month
    select Cast(Convert(varchar, DateAdd(Day,-1,'2020-08-15'),101) + ' 12:00pm' as DateTime)
    -- Output - 2020-08-14 12:00:00.000 - Previous day 
    

    This can also be done with below simple queries, just that you need handle data types and formats

    select EOMONTH('2020-08-15')
    select DATEADD(day,-1,'2020-08-15')
    

    Please don't forget to Accept Answer and Up-vote if the response helped -- Vaibhav

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.