Weird date format problem

  • Thread starter Thread starter Coleen
  • Start date Start date
C

Coleen

Hi all :-)

I have a bit of code that chacks for the last day of the Month, and if it falls on a week-end, sets the due date to the Monday after...

I'm trying to get the date to go to the Tuesday afterward, if the last day of the month falls on the week-end and the Monday afterwards is a holiday... to test I set the date to 11/30/2006, to make the due date fall on 12/31/2006 which is a Sunday and makes 1/1/2007 a holiday.

I've put in the following code:

If ls_day = "Sunday" Then
ld_due_dt = DateAdd(DateInterval.Day, 1, ld_rpt_date)
ld_holiday = Format(ld_due_dt, "MM/dd")
If ld_holiday = "01/01" Or ld_holiday = "05/31" _
Or ld_holiday = "09/01" Or ld_holiday = "11/30" Then
If ls_day = "Monday" Then
ld_due_dt = DateAdd(DateInterval.Day, 1, ld_rpt_date)
lbl_due.Text = ld_due_dt
End If
End If
Else
lbl_due.Text() = ls_duedate
End If

For some reason, the ld_holiday date keeps coming back with the value of #1/1/2004# Weird. How can I get it to come back with 1/1/2007, so I can test? TIA

Coleen
 
Use the string.format instead...


String.Format("{0:MM/dd/yy}", mydatevalue)

<I *think* this works, you may have to modify the '/'>

Hi all :-)

I have a bit of code that chacks for the last day of the Month, and if it
falls on a week-end, sets the due date to the Monday after...
I'm trying to get the date to go to the Tuesday afterward, if the last day
of the month falls on the week-end and the Monday afterwards is a holiday...
to test I set the date to 11/30/2006, to make the due date fall on
12/31/2006 which is a Sunday and makes 1/1/2007 a holiday.
I've put in the following code:

If ls_day = "Sunday" Then
ld_due_dt = DateAdd(DateInterval.Day, 1, ld_rpt_date)
ld_holiday = Format(ld_due_dt, "MM/dd")
If ld_holiday = "01/01" Or ld_holiday = "05/31" _
Or ld_holiday = "09/01" Or ld_holiday = "11/30" Then
If ls_day = "Monday" Then
ld_due_dt = DateAdd(DateInterval.Day, 1, ld_rpt_date)
lbl_due.Text = ld_due_dt
End If
End If
Else
lbl_due.Text() = ls_duedate
End If

For some reason, the ld_holiday date keeps coming back with the value of
#1/1/2004# Weird. How can I get it to come back with 1/1/2007, so I can
test? TIA
engine supports Post Alerts, Ratings, and Searching.
 
sorry, that was 4 y's on my last post...

yyyy gives you 2007

yy gives you 07

or whateer.

Hi all :-)

I have a bit of code that chacks for the last day of the Month, and if it
falls on a week-end, sets the due date to the Monday after...
I'm trying to get the date to go to the Tuesday afterward, if the last day
of the month falls on the week-end and the Monday afterwards is a holiday...
to test I set the date to 11/30/2006, to make the due date fall on
12/31/2006 which is a Sunday and makes 1/1/2007 a holiday.
I've put in the following code:

If ls_day = "Sunday" Then
ld_due_dt = DateAdd(DateInterval.Day, 1, ld_rpt_date)
ld_holiday = Format(ld_due_dt, "MM/dd")
If ld_holiday = "01/01" Or ld_holiday = "05/31" _
Or ld_holiday = "09/01" Or ld_holiday = "11/30" Then
If ls_day = "Monday" Then
ld_due_dt = DateAdd(DateInterval.Day, 1, ld_rpt_date)
lbl_due.Text = ld_due_dt
End If
End If
Else
lbl_due.Text() = ls_duedate
End If

For some reason, the ld_holiday date keeps coming back with the value of
#1/1/2004# Weird. How can I get it to come back with 1/1/2007, so I can
test? TIA
engine supports Post Alerts, Ratings, and Searching.
 
The problem is that I want to format the date so that it doesn't matter what year it is... so the date comes up formatted as "MM/dd" with out ANY year because it needs to be specific to the month and day only. I just keep getting the date returned as MM/dd/yyyy. I'll try it with the String format you've suggested, and see if that will allow me to pass the date without the year...

Thanks :-)
 
I tried using:

ld_holiday = Format(ld_due_dt.ToShortDateString, "MM/dd")

This doesn't work because I am using a date format, not a string format. Any suggestion on how to convert this to a string correctly to allow me to format it?

TIA

Coleen
 
Coleen,
In addition to CJ's comments.

Which version of the framework are you using? VS.NET 2002 & .NET 1.0 or
VS.NET 2003 & .NET 1.1?

How is ld_holiday defined? It appears to be a string.

Dim ld_holiday As String
ld_holiday = Format(ld_due_dt, "MM/dd")

Gives "01/01" in VS.NET 2003. If you defined ld_holiday as a Date, then
"There's the rub"!

You are not using Option Strict On, so VB.NET will convert the string
"01/01" to a date for you, seeing as "01/01" does not include a Year, one
will be supplied for you.

I would recommend you use Option Strict On, and declare the ld_holiday as
the correct type for how you are using it. Based on your code snippet its a
string!

Hope this helps
Jay

Hi all :-)

I have a bit of code that chacks for the last day of the Month, and if it
falls on a week-end, sets the due date to the Monday after...
I'm trying to get the date to go to the Tuesday afterward, if the last day
of the month falls on the week-end and the Monday afterwards is a holiday...
to test I set the date to 11/30/2006, to make the due date fall on
12/31/2006 which is a Sunday and makes 1/1/2007 a holiday.
I've put in the following code:

If ls_day = "Sunday" Then
ld_due_dt = DateAdd(DateInterval.Day, 1, ld_rpt_date)
ld_holiday = Format(ld_due_dt, "MM/dd")
If ld_holiday = "01/01" Or ld_holiday = "05/31" _
Or ld_holiday = "09/01" Or ld_holiday = "11/30" Then
If ls_day = "Monday" Then
ld_due_dt = DateAdd(DateInterval.Day, 1, ld_rpt_date)
lbl_due.Text = ld_due_dt
End If
End If
Else
lbl_due.Text() = ls_duedate
End If

For some reason, the ld_holiday date keeps coming back with the value of
#1/1/2004# Weird. How can I get it to come back with 1/1/2007, so I can
test? TIA
engine supports Post Alerts, Ratings, and Searching.
 
Microsoft.VisualBasic.Format != String.Format

ld_holiday = String.Format("{0:MM/dd}", ld_due_dt)

DotNetJunkies User said:
I tried using:

ld_holiday = Format(ld_due_dt.ToShortDateString, "MM/dd")

This doesn't work because I am using a date format, not a string format.
Any suggestion on how to convert this to a string correctly to allow me to
format it?
TIA

Coleen
engine supports Post Alerts, Ratings, and Searching.
 
CJ,
I suspect that ld_holiday is a Date (the "d" in "ld").

As both both Format & String.Format give the answer she suggests when I make
ld_holiday a date. Both work when I make ld_holiday a string...

I don't think its the format that is tripping her up as much as the
destination (the type of ld_holiday itself).

Just a thought
Jay
 
Ahh I missed that earlier... My apologies, yeah, little things like that
could cause problems. =)

Your option strict comment makes sense now. =) Sorry.

-CJ
 
I'm using .Net Framework v 1.0

ld_holiday was defined as a date, I changed it to a string. Here is what I ended up with, in case someone else has this type of problem. Note, I defined two ls_day vairables in order to get the day of the week if the holiday falls on a Sunday...

I ended up using the "dd-MMMM" format instead of "MM/dd" it works...

Private Sub get_due_date()
Dim ls_rpt_date, ls_day, ls_duedate, ls_holiday, ls_due, ls_day2 As String
Dim ld_date, ld_rpt_date, ld_holiday, ld_day2 As Date

ld_date = Session("rptprd")
ls_rpt_date = Format(ld_date, "MM/dd/yyyy")
ld_rpt_date = (EndOfMonth(ls_rpt_date, 1).ToString) ' add one month to the current report period end date
ls_duedate = Format(ld_rpt_date, "MM/dd/yyyy")
ls_day = Format(ld_rpt_date, "dddd")

If ls_day = "Saturday" Then
pd_due_dt = DateAdd(DateInterval.Day, 2, ld_rpt_date)
lbl_due_dt.Text = pd_due_dt
ElseIf ls_day = "Sunday" Then
pd_due_dt = DateAdd(DateInterval.Day, 1, ld_rpt_date)
ls_due = Format(pd_due_dt, "dd-MMMM")
ld_day2 = pd_due_dt
ls_holiday = ls_due
If ls_holiday = "01-January" Or ls_holiday = "31-May" Or ls_holiday = "01-September" Or ls_holiday = "30-November" Then
ls_day2 = Format(ld_day2, "dddd")
If ls_day2 = "Monday" Then
pd_due_dt = DateAdd(DateInterval.Day, 1, pd_due_dt)
lbl_due_dt.Text = pd_due_dt
End If
Else
lbl_due_dt.Text() = ls_duedate
End If
End If
End Sub
 
Back
Top