Solved

Date Problems

Posted on 2009-05-20
3
174 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

735 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