PC Review


Reply
Thread Tools Rate Thread

date conversion....

 
 
Eric @ BP-EVV
Guest
Posts: n/a
 
      29th Oct 2008
The following formula works fine in an excel spreadsheet:

=(RIGHT(YEAR(TODAY()),2)&TEXT(TODAY()-DATE(YEAR(TODAY()),1,0),"000"))+100000

to convert today's date to my company's version of a Julian date.

10/29/2008 = 108303

I'm trying to do this calculation "on the fly" within VB code since I need
the converted date in order to execute a SQL statement against our AS/400
database to return data to Excel.

I can't seem to get it right....

dim effdate as long

effdate =
application.worksheetfunction.(RIGHT(YEAR(TODAY()),2)&TEXT(TODAY()-DATE(YEAR(TODAY()),1,0),""000""))+100000

doesn't seem to cut it.....any ideas ??

Thanks !
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      29th Oct 2008
This formula seems to do the same as your worksheet formula:

=1000*(YEAR(TODAY())-1900)+TODAY()-DATE(YEAR(TODAY()),1,0)

This worked ok in code:

Dim EffDate As Long
EffDate = 1000 * (Year(Date) - 1900) + Date - DateSerial(Year(Date), 1, 0)
MsgBox EffDate



Eric @ BP-EVV wrote:
>
> The following formula works fine in an excel spreadsheet:
>
> =(RIGHT(YEAR(TODAY()),2)&TEXT(TODAY()-DATE(YEAR(TODAY()),1,0),"000"))+100000
>
> to convert today's date to my company's version of a Julian date.
>
> 10/29/2008 = 108303
>
> I'm trying to do this calculation "on the fly" within VB code since I need
> the converted date in order to execute a SQL statement against our AS/400
> database to return data to Excel.
>
> I can't seem to get it right....
>
> dim effdate as long
>
> effdate =
> application.worksheetfunction.(RIGHT(YEAR(TODAY()),2)&TEXT(TODAY()-DATE(YEAR(TODAY()),1,0),""000""))+100000
>
> doesn't seem to cut it.....any ideas ??
>
> Thanks !


--

Dave Peterson
 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      29th Oct 2008
Dim effdate
effdate = (100000 + (Right(Year(Date), 2) & Format(Date -
DateSerial(Year(Date), 1, 0), "000")))


--
__________________________________
HTH

Bob

"Eric @ BP-EVV" <(E-Mail Removed)> wrote in message
news:1997E278-2987-494B-8326-(E-Mail Removed)...
> The following formula works fine in an excel spreadsheet:
>
> =(RIGHT(YEAR(TODAY()),2)&TEXT(TODAY()-DATE(YEAR(TODAY()),1,0),"000"))+100000
>
> to convert today's date to my company's version of a Julian date.
>
> 10/29/2008 = 108303
>
> I'm trying to do this calculation "on the fly" within VB code since I need
> the converted date in order to execute a SQL statement against our AS/400
> database to return data to Excel.
>
> I can't seem to get it right....
>
> dim effdate as long
>
> effdate =
> application.worksheetfunction.(RIGHT(YEAR(TODAY()),2)&TEXT(TODAY()-DATE(YEAR(TODAY()),1,0),""000""))+100000
>
> doesn't seem to cut it.....any ideas ??
>
> Thanks !



 
Reply With Quote
 
dmoney
Guest
Posts: n/a
 
      29th Oct 2008
why not use excel to get the value and put it in a variable to pass to the
AS400 code?

Dim a As Variant
Range("a1").Select
ActiveCell.FormulaR1C1 = _

"=(RIGHT(YEAR(TODAY()),2)&TEXT(TODAY()-DATE(YEAR(TODAY()),1,0),""000""))+100000"
a = ActiveCell.Value
Selection.ClearContents

u can use the variable a to pass the result.

HTH


"Eric @ BP-EVV" wrote:

> The following formula works fine in an excel spreadsheet:
>
> =(RIGHT(YEAR(TODAY()),2)&TEXT(TODAY()-DATE(YEAR(TODAY()),1,0),"000"))+100000
>
> to convert today's date to my company's version of a Julian date.
>
> 10/29/2008 = 108303
>
> I'm trying to do this calculation "on the fly" within VB code since I need
> the converted date in order to execute a SQL statement against our AS/400
> database to return data to Excel.
>
> I can't seem to get it right....
>
> dim effdate as long
>
> effdate =
> application.worksheetfunction.(RIGHT(YEAR(TODAY()),2)&TEXT(TODAY()-DATE(YEAR(TODAY()),1,0),""000""))+100000
>
> doesn't seem to cut it.....any ideas ??
>
> Thanks !

 
Reply With Quote
 
Eric @ BP-EVV
Guest
Posts: n/a
 
      29th Oct 2008
Dave - that's awesome....exactly what I needed.

Thanks !

Eric

"Dave Peterson" wrote:

> This formula seems to do the same as your worksheet formula:
>
> =1000*(YEAR(TODAY())-1900)+TODAY()-DATE(YEAR(TODAY()),1,0)
>
> This worked ok in code:
>
> Dim EffDate As Long
> EffDate = 1000 * (Year(Date) - 1900) + Date - DateSerial(Year(Date), 1, 0)
> MsgBox EffDate
>
>
>
> Eric @ BP-EVV wrote:
> >
> > The following formula works fine in an excel spreadsheet:
> >
> > =(RIGHT(YEAR(TODAY()),2)&TEXT(TODAY()-DATE(YEAR(TODAY()),1,0),"000"))+100000
> >
> > to convert today's date to my company's version of a Julian date.
> >
> > 10/29/2008 = 108303
> >
> > I'm trying to do this calculation "on the fly" within VB code since I need
> > the converted date in order to execute a SQL statement against our AS/400
> > database to return data to Excel.
> >
> > I can't seem to get it right....
> >
> > dim effdate as long
> >
> > effdate =
> > application.worksheetfunction.(RIGHT(YEAR(TODAY()),2)&TEXT(TODAY()-DATE(YEAR(TODAY()),1,0),""000""))+100000
> >
> > doesn't seem to cut it.....any ideas ??
> >
> > Thanks !

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Conversion Solar date to Gregorian Mohammad Mobin Microsoft Access Forms 2 4th Jan 2010 06:22 PM
Date Conversion from General Date to Short Date =?Utf-8?B?QnJpYW4gQw==?= Microsoft Access Queries 3 12th Jun 2007 05:03 PM
Date conversion -- what date is B04FC6954E6BC501D9? =?Utf-8?B?RGF2aWQgTW9zcw==?= Microsoft Access VBA Modules 3 7th Nov 2006 12:14 PM
Date Conversion =?Utf-8?B?QmVlSmF5?= Microsoft Access Queries 5 17th Jun 2005 02:50 AM
Date conversion, hijri date jmassry Microsoft Access Form Coding 1 24th Jun 2004 10:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:15 AM.