473,399 Members | 4,254 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,399 software developers and data experts.

Date Subtraction/Formatting Issues

This worked in VB6, but does not in VB.Net

Format(MyDate - DateSerial(Year(MyDate) - 1, 12, 31), "000")

Where:
MyDate is type Date and = #11/16/2003#

It should return the Julian Day # --> 321

But I get an error "Specified cast is not allowed"

Any help here??

Thanks,
David
Nov 20 '05 #1
4 2520
"David Doing" <do***@cny-golf.com> schrieb
This worked in VB6, but does not in VB.Net

Format(MyDate - DateSerial(Year(MyDate) - 1, 12, 31), "000")

Where:
MyDate is type Date and = #11/16/2003#

It should return the Julian Day # --> 321

But I get an error "Specified cast is not allowed"

Any help here??


(MyDate.Subtract(New Date(MyDate.Year, 12, 31))).ToString("000")
Maybe you like the shorter version: ;-)

MyDate.DayOfYear.ToString("000")
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
See, its so much easier in .NET!!

Thanks Armin

"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
"David Doing" <do***@cny-golf.com> schrieb
This worked in VB6, but does not in VB.Net

Format(MyDate - DateSerial(Year(MyDate) - 1, 12, 31), "000")

Where:
MyDate is type Date and = #11/16/2003#

It should return the Julian Day # --> 321

But I get an error "Specified cast is not allowed"

Any help here??


(MyDate.Subtract(New Date(MyDate.Year, 12, 31))).ToString("000")
Maybe you like the shorter version: ;-)

MyDate.DayOfYear.ToString("000")
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
Hi David,

You may try to use the code below.
[VB.NET]
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles Command1.Click
Dim ss As String
Dim MyDate As Date
MyDate = #11/16/2003#
ss = Format(DateTime.FromOADate(MyDate.ToOADate -
DateSerial(Year(MyDate) - 1, 12, 31).ToOADate), "000")
MsgBox(ss)
End Sub

[VB6]
Private Sub Command1_Click()
Dim MyDate As Date
MyDate = #11/16/2003#
ss = Format(MyDate - DateSerial(Year(MyDate) - 1, 12, 31), "000")
MsgBox ss
End Sub

FYI
All the two sample will return 320, NOT 321.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #4
Worked like a charm, thank you.
David
"Peter Huang" <v-******@online.microsoft.com> wrote in message
news:sA**************@cpmsftngxa06.phx.gbl...
Hi David,

You may try to use the code below.
[VB.NET]
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles Command1.Click
Dim ss As String
Dim MyDate As Date
MyDate = #11/16/2003#
ss = Format(DateTime.FromOADate(MyDate.ToOADate -
DateSerial(Year(MyDate) - 1, 12, 31).ToOADate), "000")
MsgBox(ss)
End Sub

[VB6]
Private Sub Command1_Click()
Dim MyDate As Date
MyDate = #11/16/2003#
ss = Format(MyDate - DateSerial(Year(MyDate) - 1, 12, 31), "000")
MsgBox ss
End Sub

FYI
All the two sample will return 320, NOT 321.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: J. Muenchbourg | last post by:
I have scripts on a server that awhile back had new option/server packs installed (to accomodate security and net framework issues) and my classic asp date references "Date()" and "Now" will...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
0
by: J. Muenchbourg | last post by:
I have scripts on a server that awhile back had new option/server packs installed (to accomodate security and net framework issues) and my classic asp date references "Date()" and "Now" will...
1
by: sylvian stone | last post by:
Hi, I've used standard date functions in the past, but need to create something a little different, as I am working on an investment calculator. What I need to do is validate two dates, and...
5
by: middletree | last post by:
Is there a script that will populate, with a click, a textbox with the equivalent of the ASP/VBScript Now() function? In ohter words, I'd like it to be in this format: 7/25/2005 10:58:39 AM
2
by: Kevin Thomas | last post by:
Hello, I have a date value in a table SQL Server database that looks like this: 2005-10-11 12:54:36.860 When I load the record into a dataset in VB.NET and retrieve the date value into code,...
7
by: Andy Davis | last post by:
I have a table of data in Access 2002 which is used as the source table for a mail merge document using Word 2002 on my clients PC. The data is transferred OK but I've noticed that any dates which...
4
by: dhnriverside | last post by:
Hi peeps I have a datepicker control that's providing dates in the format dd/mm/yyyy (UK). I want to convert this to "yyyy-mm-dd" to store as a text field in my database (had lots of problems...
5
by: Keflavich | last post by:
Hey, I have a bit of code that died on a domain error when doing an arcsin, and apparently it's because floating point subtraction is having problems. I know about the impossibility of storing...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.