By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,578 Members | 1,626 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,578 IT Pros & Developers. It's quick & easy.

DateTime structure

P: n/a
Hello

Is it possible to create a DateTime structure that does not include the
date? I am only intrested in the time and day. for example 23:00 Mon. I
would eventually like to add and subtract hours to based on a UTC
calculation.

any help is greatly appreciated.

Feb 14 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Arrrrgg!!! this is so frustrating.

I am trying the following

Dim MyTime As System.DateTime
MyTime = System.DateTime.Parse("8:00 mon")
MyTime = MyTime.AddHours(-11)
MyTime = MyTime.AddHours(-5)
MsgBox(MyTime.ToString("HH:mm ddd"))

but it only works on the day equivelant to today, in this case monday..
If I plug in 8:00 Tue through sun it errors. Is there any way to
accomplish this? It seems to still be bound to a date. I am trying to
convert a shift schedule from Sydney time, to Eastern. I do not care
about the date, just the day ranges and hours.

Is there any way to do this?

Feb 14 '06 #2

P: n/a
I think that, for this exercise, because the date is irrelevant, you need to
create your own class that does some number crunching without using DateTime
structures at all.

Using the example you have given, it might be something like:

Public Class MyScheduleItem

Public Shared Function ConvertLocalToRemote(ByVal LocalTimeOfDay As
Integer, ByVal LocalDayOfWeek As DayOfWeek, ByVal RemoteOffset As Integer)
As String

Dim _RemoteTimeOfDay As Integer = LocalTimeOfDay + RemoteOffset

Dim _RemoteDayOfWeek As DayOfWeek = LocalDayOfWeek

Select Case _RemoteTimeOfDay
Case < 0
_RemoteDayOfWeek = CType(Convert.ToInt32(_RemoteDayOfWeek) - 1,
DayOfWeek)
_RemoteTimeOfDay = 1440 + _RemoteTimeOfDay
Case >= 1440
_RemoteDayOfWeek = CType(Convert.ToInt32(_RemoteDayOfWeek) + 1,
DayOfWeek)
End Select

Select case _RemoteDayOfWeek
Case < DayOfWeek.Sunday
_RemoteDayOfWeek = DayOfWeek.Saturday
Case > DayOfWeek.Saturday
_RemoteDayOfWeek = DayOfWeek.Sunday
End Select

Return String.Format("{0:#0}:{1:00} {2}", Fix(_RemoteTimeOfDay \ 60) ,
_RemoteTimeOfDay Mod 60, _RemoteDayOfWeek.ToString.SubString(0,3))

End Sub

End Class

Note that LocalTimeOfDay, _RemoteTimeOfDay and RemoteOffset are in units of
minutes thus handling times of day and offsets that are not whole hours.

Note also that the week is deemed to run from Sunday (0) to Saturday (6).

Call it with:

Console.WriteLine(MyScheduleItem.ConvertLocalToRem ote(8 * 60,
DayOfWeek.Monday, -(16 * 60)))

Dissect it to your hearts content to see how it works and improve on it.
"Paulers" <Su*******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Arrrrgg!!! this is so frustrating.

I am trying the following

Dim MyTime As System.DateTime
MyTime = System.DateTime.Parse("8:00 mon")
MyTime = MyTime.AddHours(-11)
MyTime = MyTime.AddHours(-5)
MsgBox(MyTime.ToString("HH:mm ddd"))

but it only works on the day equivelant to today, in this case monday..
If I plug in 8:00 Tue through sun it errors. Is there any way to
accomplish this? It seems to still be bound to a date. I am trying to
convert a shift schedule from Sydney time, to Eastern. I do not care
about the date, just the day ranges and hours.

Is there any way to do this?

Feb 14 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.