Wrox Programmer Forums
|
Other Programming Languages If you have a coding issue to discuss about another language that really isn't provided for in any other forum here (not ASP.NET C#, C++, VB, PHP, JavaScript, Python, Java, Perl, Applescript, XML or any of the other forum topics we have), post it here. Enough discussion on a language we don't have covered could prompt a new forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Other Programming Languages section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 9th, 2005, 02:49 PM
Registered User
 
Join Date: Dec 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to frankb522
Default SQL date functions

This didn't really fit in the SQL Server section so I'll ask here. I have a report that every month I have to hardcode the first and last days of the month to run it. Is there a function like LASTDAY and FIRSTDAY that I can let the report run without intervention?

Frank
Reply With Quote
  #2 (permalink)  
Old March 1st, 2006, 01:13 PM
Authorized User
 
Join Date: Mar 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I would post in the SQL forum since you're
getting no response here.

Reply With Quote
  #3 (permalink)  
Old June 24th, 2006, 09:04 AM
Authorized User
 
Join Date: Jun 2006
Posts: 73
Thanks: 1
Thanked 1 Time in 1 Post
Default

I suggest the following. As the 'run-time' of the report is within the month in whch the dates are that you wish to set, add some variable to the S.Q.L. e.g.

Dim sqlstrng as String, d1, d2 as Date

Add your code here for your algorithm as normal.....

d1 = Date
d2 = Date ' This sets d1 & d2 to the current system date i.e.today.
Do
   If CByte(Val(Mid(Format(d1, "dd/mm/yyyy")), 2,1)) > 1 Then
      GoTo 1
   Else
      ' this repeatedly subtracts a day at a time from 'today's date until the first of the month is reached
      d1 = d1 - 1
   End If
Loop
Do

    ' likewise do the same for d2, only add one each time in the loop until the last day of the month is reached,(You may have to have further 'If' checks depending on whether there are 30, 31, 28, or 29 days in the current month)

Loop

sqlstrng = "SELECT (add fields, table etc.) FROM (add Table(s)) WHERE reportdates BETWEEN #" & d1 & "# AND #" & d2 & "#;"

I hope this helps. liamfitz.

Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
date functions in xslt1.0 pradeepn XSLT 4 July 26th, 2007 04:28 AM
SQL Functions jezywrap ASP.NET 2.0 Professional 2 December 26th, 2006 05:30 PM
Date functions Gandalf_the_Grey Classic ASP Basics 2 December 20th, 2006 02:39 AM
DATE FUNCTIONS DARSIN General .NET 1 January 14th, 2005 09:11 AM
Date functions and statements Thomas82 Classic ASP Professional 3 June 29th, 2004 10:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.