# (VBScript) Format Date

**URL:** https://www.finalbuilder.com/forums/t/vbscript-format-date/4363
**Category:** Discussion
**Created:** [March 25, 2009, 1:25am UTC](https://www.finalbuilder.com/forums/t/vbscript-format-date/4363 "2009-03-25T01:25:03Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![matthiaskramer](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/m/8dc957/32.png) [@matthiaskramer](https://www.finalbuilder.com/forums/u/matthiaskramer)
#### Post date: [March 25, 2009, 1:25am UTC](https://www.finalbuilder.com/forums/t/vbscript-format-date/4363/1 "2009-03-25T01:25:03Z")

</div>

Hi,

i have a script that copies files into a directory.

The directory is like "Archive/2009/March/Mon 23"

So the directories are the current date and i let automise create that dirs... no problem here.

But sometimes i have to archive the files from yesterday so i compare the date and if its a new day and no files are copied, i will do it then. I have to create the dirs with the date from yesterday but i dont know how. I know that i have to use VBScript to find out the date from yesterday but i dont really know VBScript.

I tried it that way:

DateYesterday = Format(Date, "yyyymmdd")  
DateYDay = Format(Day(Date() -1), "00")  
DateYDayShort = Format(Day(Date() -1), "000")  
DateYMonth = Format(Month(Date() -1), "00")  
DateYYear = Format(Year(Date() -1), "00")

But it seems that i have a problem with "Format"

Anyone who can help me out?

Regards,

Matthias

---

<div class="post-metadata">

### Author: ![paulsamways](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@paulsamways](https://www.finalbuilder.com/forums/u/paulsamways)
#### Post date: [March 25, 2009, 11:57am UTC](https://www.finalbuilder.com/forums/t/vbscript-format-date/4363/2 "2009-03-25T11:57:52Z")

</div>

Hi Matthias,   
  
 Here’s some example date functions in VBScript which should get you the required values:   
  
 Dim Yesterday   
  
 Yesterday = DateAdd(“d”, -1, Now)   
  
 alert(Year(Yesterday))   
 alert(Day(Yesterday))   
 alert(WeekdayName(Weekday(Yesterday)))   
 alert(Month(Yesterday))   
 alert(MonthName(Month(Yesterday), False))

---

<div class="post-metadata">

### Author: ![matthiaskramer](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/m/8dc957/32.png) [@matthiaskramer](https://www.finalbuilder.com/forums/u/matthiaskramer)
#### Post date: [April 1, 2009, 8:12am UTC](https://www.finalbuilder.com/forums/t/vbscript-format-date/4363/3 "2009-04-01T08:12:57Z")

</div>

Works like a charm.   
 Thank you very much!
