I have a not null column in table where its saving current date and time using getDate function in SQL by default.
Now I'd like to generate reports. Am using MicrosoftReportViewer.
Would like to give a DateTimePicker, where the person can select the year, date or change any perspective of date. It should check the getDate() of that column in database and update the report based on that date.
Is that easily implementable? - As I have very short span of time left.
DateTime in C# - GetDate in SQL - A small confusion
Re: DateTime in C# - GetDate in SQL - A small confusion
Add your date/time field as a Report Parameter and do something as below.
VB.Net code
VB.Net code
Code: Select all
Dim params(0) As Microsoft.Reporting.WebForms.ReportParameter
Dim p As Microsoft.Reporting.WebForms.ReportParameter
p = New Microsoft.Reporting.WebForms.ReportParameter("YourField", dtpicker1.value)
params(0) = p
ReportViewer1.ServerReport.SetParameters(params)
ReportViewer1.ServerReport.Refresh()
Re: DateTime in C# - GetDate in SQL - A small confusion
Find a good example in C# here.
Re: DateTime in C# - GetDate in SQL - A small confusion
Just a small question about DateTime - I have smalldatetime stored in sql database table.
Now I'd like to compare the month part of DateTimePicker with the databased stored date. How to compare the month of DateTimePicker with that of database table value.
Please help asap.
Now I'd like to compare the month part of DateTimePicker with the databased stored date. How to compare the month of DateTimePicker with that of database table value.
Please help asap.
Re: DateTime in C# - GetDate in SQL - A small confusion
Let me ask it if something with substr is possible. I am okay if I can add a column to the table using substr and get only the month part of it.
But am not able to successfully achieve this. Need help.
Thank you.
But am not able to successfully achieve this. Need help.
Thank you.
Re: DateTime in C# - GetDate in SQL - A small confusion
SELECT * FROM table1 WHERE MONTH(field1) = dtpicker1.value.month()
Similarly you could use, DAY, YEAR to get day or year part of the field.
If you need to get more parts of date/time, you can use DATEPART function as below.
SQL Syntax: DATEPART ( datepart , date field )
To get month, we need to use 'm' abbreviations as below.
SELECT * FROM table1 WHERE DATEPART (m, field1) = dtpicker1.value.month()
Instead of m, you can use several datepart abbreviations as below.
Similarly you could use, DAY, YEAR to get day or year part of the field.
If you need to get more parts of date/time, you can use DATEPART function as below.
SQL Syntax: DATEPART ( datepart , date field )
To get month, we need to use 'm' abbreviations as below.
SELECT * FROM table1 WHERE DATEPART (m, field1) = dtpicker1.value.month()
Instead of m, you can use several datepart abbreviations as below.
datepart | Abbreviations |
year | yy, yyyy |
quarter | qq, q |
month | mm, m |
dayofyear | dy, y |
day | dd, d |
week | wk, ww |
weekday | dw |
hour | hh |
minute | mi, n |
second | ss, s |
millisecond | ms |
microsecond | mcs |
nanosecond | ns |
TZoffset | tz |
ISO_WEEK | isowk, isoww |