Solved

Date Problems

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.net Open Folder in Windows Explorer 3 50
VB.net capture  result of a SQL query in variables 3 20
FInd Image Control Gridview 3 19
Groupbox Control ? 2 17
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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

790 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