Solved

Date Problems

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

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 …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now