Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Date Problems

Posted on 2009-05-20
3
Medium Priority
?
179 Views
Last Modified: 2012-05-07
Afternoon,

I have a date in my database that is dd/mm/yyyy and I want to be able to in my vb.net program get the first day and last day of current month.

How can I do this?

SELECT * FROM tblPLUSales WHERE siteid = '1' and datestamp = 'startofmonth' between datestamp = 'endofmonth'
0
Comment
Question by:richard_gar
3 Comments
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 24433107
Mmm... poorly explained. Explain your problem better, please. What do you want? An SQL sentence? VB.net code? What type of field stores the date value?
0
 

Author Comment

by:richard_gar
ID: 24433120
all I want to know is how to get in vb.net code the start of current month and the end of the current month.

01/05/2009 - 31/05/2009
0
 
LVL 15

Accepted Solution

by:
oobayly earned 2000 total points
ID: 24433153
Use the following to get the date range for the current month, and use them as the parameters in the query.
Assuming you're using the System.Data.SqlClient namespace, but the same applies for any adapters.
Dim startDate As New DateTime(DateTime.Today.Year, DateTime.Today.Month, 1)
Dim endDate As DateTime = startDate .AddMonths(1).AddDays(-1)
 
Dim query As New SqlCommand("SELECT * FROM tblPLUSales WHERE siteid = '1' " & _
  "AND datestamp BETWEEN @startDate AND @endDate", sqlConn)
query.Parameters.AddWithValue("startDate", startDate)
query.Parameters.AddWithValue("endDate", endDate)

Open in new window

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question