0

Update: End Goal:

Show May 10th - June 8th, all dates in between with the Prefix May or June (month name). Which ever date is today.. something like border around that calendar day (style stuff) So outputs all dates in between, each day the 'date' in which is today is highlighted. Outputs like a calendar, with various (unique images) per calendar day (in between described date range). Add specific styles to calendar day that is 'today'. So if it's the 11th, specific styles to May 11th are visible in that calendar region -- if June 2nd the same.


I can do this within one month / same month; with the below, but now it's not so simple, because my date range is in between two months. May 10th - June 8th. How can I split into two arrays - and it's not just a date range; I need to detect if day is today.

<%
    For i = 10 to 31
    dim time
    If i < day_part Then
    time = "past"
    ElseIf i = day_part Then
    time = "today"
    Else
    time = "future"
    End If
    suffix = Suffixer(i)

    response.write("<section id='day_"& i &"' class='calSquare  " & time &"'><article class='dateImage' style='background-image: url(images/Calendar_Thumbnails/Day_"&i&".jpg)'></article></article><article class='dateTitle'> "&i&suffix&"</article></section>")

    Next
    <!--response.write(products(0))-->
%>

Latest code via answered suggestion below (others have reviewed it may not be valid VBscript but only suggestion I got):

<%
    Dim d1 As New Date(2015, 5, 10)
    Dim d2 As New Date(2015, 6, 8)

    Dim DaysBetween As Long = DateDiff(DateInterval.Day, d1, d2)

    Dim d3 As Date

    For d As Long = 0 To DaysBetween
        d3 = d1.AddDays(d)

        If d3 < Today() Then
        ElseIf d3 = Today Then
        Else
        End If

        Dim suffix As String = Suffixer(d3.Day)

        Next

        response.write("<section id='day_"& d &"' class='calSquare  " & time &"'><article class='dateImage' style='background-image: url(images/Calendar_Thumbnails/Day_"&d&".jpg)'></article></article><article class='dateTitle'> "&d&suffix&"</article></section>")

        <!--response.write(products(0))-->
    %>

*I have replaced i with d across the board (with above attempt) -- and didn't work! I have updated my question with the latest code as well. I've gotten feedback that the logic is correct but may not be valid VBscript with constructs being used. Any other suggestions would be amazing!*

Dr Upvote
  • 8,023
  • 24
  • 91
  • 204
  • 1
    What exactly are you trying to do? – Jim Mischel Apr 27 '15 at 21:40
  • Show May 10th - June 8th. If a certain date in between; specific content. So outputs all dates in between, each day the 'date' in which is today is highlighted. – Dr Upvote Apr 27 '15 at 21:41
  • Sorry, but the phrasing of your question makes it about as clear as mud, and I have no idea what much of that code is about or how it relates to your question. Please read [how to ask](http://stackoverflow.com/help/how-to-ask), and then create a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Matt Johnson-Pint Apr 27 '15 at 21:50
  • 1
    So your primary problem is how to enumerate all of the days between two dates. So if your date range is May 10 through June 8, then you want May 10, 11, 12...31, and then June 1, 2, 3 ... 8? And you want to do this in vbscript? You might have better luck if you removed the .net tag and added a vbscript tag. And simplified your question. Your update just confuses the issue even more. – Jim Mischel Apr 27 '15 at 22:10

2 Answers2

1

Rule #27: don't use Integers when you mean Dates:

Here - go play - I'll leave it to you to fill in the blanks and debug:

    Dim d1 As New Date(2015, 5, 10)
    Dim d2 As New Date(2015, 6, 8)

    Dim DaysBetween As Long = DateDiff(DateInterval.Day, d1, d2)

    Dim d3 As Date

    For d As Long = 0 To DaysBetween
        d3 = d1.AddDays(d)

        If d3 < Today() Then
        ElseIf d3 = Today Then
        Else
        End If

        Dim suffix As String = Suffixer(d3.Day)
    Next
fnostro
  • 4,531
  • 1
  • 15
  • 23
  • This looks amazing, and is exactly what I'm looking for code wise -- but it doesn't work with my 'response.write' underneath. – Dr Upvote Apr 28 '15 at 14:31
  • I have replaced i with d across the board -- and didn't work man! I have updated my question with the latest code as well. – Dr Upvote Apr 28 '15 at 15:42
  • In the above post I told you you need to fill the blanks and debug - if you examine your original code and the above there are key pieces missing. you really should be able to figure this out. – fnostro Apr 28 '15 at 15:56
  • Well, thanks for the suggestion and giving it a shot. – Dr Upvote Apr 29 '15 at 14:57
-1

fnostro's

Rule #27: don't use Integers when you mean Dates

is correct, but the answer violates

Rule #1: use VBScript

So if you need an answer to COOOL's question (and a solution for nearly all formatting problems in VBScript (cf. here):

Option Explicit

' !! http://csharphelper.com/blog/2014/11/convert-an-integer-into-an-ordinal-in-c/
' Return the int's ordinal extension.
Function OrdExt(value)
    ' Start with the most common extension.
    OrdExt = "th"
    ' Examine the last 2 digits.
    Dim last_digits : last_digits = value Mod 100
    ' If the last digits are 11, 12, or 13, use th. Otherwise:
    If last_digits < 11 Or last_digits > 13 Then
        ' Check the last digit.
        Select Case last_digits Mod 10
            Case 1
                OrdExt = "st"
            Case 2
                OrdExt = "nd"
            Case 3:
                OrdExt = "rd"
        End Select
    End If
End Function

' !! https://stackoverflow.com/a/11262441/603855
Class cFormat
  Private m_oSB
  Private Sub Class_Initialize()
    Set m_oSB = CreateObject("System.Text.StringBuilder")
  End Sub ' Class_Initialize
  Public Function formatOne(sFmt, vElm)
    m_oSB.AppendFormat sFmt, vElm
    formatOne = m_oSB.ToString()
    m_oSB.Length = 0
  End Function ' formatOne
  Public Function formatArray(sFmt, aElms)
    m_oSB.AppendFormat_4 sFmt, (aElms)
    formatArray = m_oSB.ToString()
    m_oSB.Length = 0
  End Function ' formatArray
End Class ' cFormat

Dim oF     : Set oF = New cFormat
Dim sFmt   : sFmt   = "<section id='day_{0}' class='calSquare {1}'><article class='dateImage' style='background-image: url(images/Calendar_Thumbnails/{2}/Day_{0}.jpg)'></article></article><article class='dateTitle'>{2} {0}{3}</article></section>"
Dim dToday : dToday = #3/1/2012#  ' fake needed for Feb 29th demo
Dim aTime  : aTime  = Split("past today future")
Dim d
For d = #2/27/2012# To #3/4/2012#
    WScript.Echo d, TypeName(d), aTime(Sgn(DateDiff("d", dToday, d)) + 1)
    WScript.Echo oF.formatArray(sFmt, Array(Day(d), aTime(Sgn(DateDiff("d", dToday, d)) + 1), MonthName(Month(d)), OrdExt(Day(d))))
Next

output:

cscript 29906416.vbs
27.02.2012 Date past
<section id='day_27' class='calSquare past'><article class='dateImage' style='background-image: url(images/Cal
endar_Thumbnails/February/Day_27.jpg)'></article></article><article class='dateTitle'>February 27th</article><
/section>
28.02.2012 Date past
<section id='day_28' class='calSquare past'><article class='dateImage' style='background-image: url(images/Cal
endar_Thumbnails/February/Day_28.jpg)'></article></article><article class='dateTitle'>February 28th</article><
/section>
29.02.2012 Date past
<section id='day_29' class='calSquare past'><article class='dateImage' style='background-image: url(images/Cal
endar_Thumbnails/February/Day_29.jpg)'></article></article><article class='dateTitle'>February 29th</article><
/section>
01.03.2012 Date today
<section id='day_1' class='calSquare today'><article class='dateImage' style='background-image: url(images/Cal
endar_Thumbnails/March/Day_1.jpg)'></article></article><article class='dateTitle'>March 1st</article></section
>
02.03.2012 Date future
<section id='day_2' class='calSquare future'><article class='dateImage' style='background-image: url(images/Ca
lendar_Thumbnails/March/Day_2.jpg)'></article></article><article class='dateTitle'>March 2nd</article></sectio
n>
03.03.2012 Date future
<section id='day_3' class='calSquare future'><article class='dateImage' style='background-image: url(images/Ca
lendar_Thumbnails/March/Day_3.jpg)'></article></article><article class='dateTitle'>March 3rd</article></sectio
n>
04.03.2012 Date future
<section id='day_4' class='calSquare future'><article class='dateImage' style='background-image: url(images/Ca
lendar_Thumbnails/March/Day_4.jpg)'></article></article><article class='dateTitle'>March 4th</article></sectio
n>
Community
  • 1
  • 1
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96