Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Date

Reply
 
Old 06-24-2009   #1 (permalink)
Larry


 
 

Date

Is there a vbs code that returns today's date?

I want to return the date in the form, "June 24" (no year).

Thanks,
Larry

My System SpecsSystem Spec
Old 06-24-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: Date

Larry wrote:
Quote:

> Is there a vbs code that returns today's date?
>
> I want to return the date in the form, "June 24" (no year).
>
The Now() function returns the current date/time. You can use other
functions to format as desired. For example:

Wscript.Echo MonthName(Month(Now())) & " " & Day(Now())

Displays the current date in the format you requested.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 06-25-2009   #3 (permalink)
Larry


 
 

Re: Date

Wscript.Echo MonthName(Month(Now())) & " " & Day(Now())

Richard,

That's great, thank you.

One other thing: How would I adjust this to get the date prior to the
current date?

I've tried inserting "-1" in different parts of the code and can't get it.

Larry

My System SpecsSystem Spec
Old 06-25-2009   #4 (permalink)
Larry


 
 

Never mind

I got it, very simple:

Wscript.Echo MonthName(Month(Now())) & " " & Day(Now()-1)
My System SpecsSystem Spec
Old 06-25-2009   #5 (permalink)
Pegasus [MVP]


 
 

Re: Never mind


"Larry" <larry328NOSPAM@xxxxxx> wrote in message
news:%230n5paV9JHA.1340@xxxxxx
Quote:

>I got it, very simple:
>
> Wscript.Echo MonthName(Month(Now())) & " " & Day(Now()-1)
This does not really work since you will have serious problems on days such
as 1 July or even worse, on 1 January. Fortunately cscript has a full set of
date arithmethic functions such as DateAdd or DateDiff. I recommend you
download the helpfile script56.chm from the Microsoft site to see how
they're used.


My System SpecsSystem Spec
Old 06-25-2009   #6 (permalink)
Steve


 
 

Re: Never mind

Pegasus [MVP] wrote:
Quote:

> "Larry" <larry328NOSPAM@xxxxxx> wrote in message
> news:%230n5paV9JHA.1340@xxxxxx
Quote:

>> I got it, very simple:
>>
>> Wscript.Echo MonthName(Month(Now())) & " " & Day(Now()-1)
>
> This does not really work since you will have serious problems on
> days such as 1 July or even worse, on 1 January. Fortunately cscript
> has a full set of date arithmethic functions such as DateAdd or
> DateDiff.
Or subtract 1 from the date first and then extract the parts:

Yesterday = Date() - 1
WScript.Echo MonthName(Month(Yesterday)) & " " & Day(Yesterday)
Quote:

> I recommend you download the helpfile script56.chm from the Microsoft
> site to see how they're used.
I endorse that recommendation!

--
Steve

Heresy is only another word for freedom of thought. -Graham Greene


My System SpecsSystem Spec
Old 06-25-2009   #7 (permalink)
Larry


 
 

Re: Never mind

Thanks.
My System SpecsSystem Spec
Old 06-25-2009   #8 (permalink)
Al Dunbar


 
 

Re: Never mind


"Steve" <cerberus40@xxxxxx> wrote in message
news:OEsZuFX9JHA.1488@xxxxxx
Quote:

> Pegasus [MVP] wrote:
Quote:

>> "Larry" <larry328NOSPAM@xxxxxx> wrote in message
>> news:%230n5paV9JHA.1340@xxxxxx
Quote:

>>> I got it, very simple:
>>>
>>> Wscript.Echo MonthName(Month(Now())) & " " & Day(Now()-1)
>>
>> This does not really work since you will have serious problems on
>> days such as 1 July or even worse, on 1 January. Fortunately cscript
>> has a full set of date arithmethic functions such as DateAdd or
>> DateDiff.
>
> Or subtract 1 from the date first and then extract the parts:
>
> Yesterday = Date() - 1
> WScript.Echo MonthName(Month(Yesterday)) & " " & Day(Yesterday)
Your suggestion above also seems to address the unlikely, but potentially
dangerous problem that the date could change between the two calling
instances of the now function.

/Al
Quote:
Quote:

>> I recommend you download the helpfile script56.chm from the Microsoft
>> site to see how they're used.
>
> I endorse that recommendation!
>
> --
> Steve
>
> Heresy is only another word for freedom of thought. -Graham Greene
>


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Date Taken and Date Modified Vista music pictures video
Modified Date used as Date Taken in Photo Gallery and Digital Imag Vista music pictures video
Photo date taken vs. file date Vista music pictures video
Date PowerShell
Blank "Date Taken / Date Modified" field in Vista Vista file management


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46