473,385 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

DateTime structure

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
2 1389
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Pram | last post by:
I am curious why did Microsoft write System.DateTime as a structure instead of a class? Maybe for backward compatibilty with any existing old code? FYI, one of the differences between...
16
by: PK9 | last post by:
I have a string variable that holds the equivalent of a DateTime value. I pulled this datetime from the database and I want to strip off the time portion before displaying to the user. I am...
1
by: Chris | last post by:
Hello, I'm having some problems right now with something that would seem to be rather simple (and probably is). But, the solution is escaping me right now. Currently, I have created a data...
44
by: Frank Rizzo | last post by:
Any ideas?
5
by: A.M | last post by:
Hi, I know we can assigne year, month and day to a DateTime value by the constructor like Dim dt As DateTime = New DateTime(2003,8,1) How can i assign value by year, month and day? I am...
13
by: Alan M Dunsmuir | last post by:
I need to specify a new data type, almost entirely a 'clone' of the existing DateTime type, with the following specific difference, and all the consequent differences in properties and methods...
3
by: asanford | last post by:
I want to create a web service that allows the caller to pass a DateTime to the web service (that is, create a web method such as void MyWebMethod(DateTime dt).) However, I want to be able to...
4
by: =?Utf-8?B?QmFidU1hbg==?= | last post by:
Hi, I have a GridView and a SqlDataSource controls on a page. The SqlDataSource object uses stored procedures to do the CRUD operations. The DataSource has three columns one of which -...
7
by: TheLostLeaf | last post by:
DateTime tTime = DateTime.Now; ------------------------------------------------------------------------------------------- tTime returns "1:59:00 PM" it never returns seconds. Database field...
5
by: indika | last post by:
Hi, I'm a newbie to python but have some experience in programming. I came across this requirement of using datetime.date objects associated with some another object. eg. a dictionary containing...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.