Solved

some date formats

Posted on 2008-10-22
3
291 Views
Last Modified: 2012-05-05
can someone explain what each of these does?

strdateFormat = CStr(Format(Today().Date, "yyyyMMdd"))

 strdateFormat = CStr(Format(Today().AddDays(0), "yyyyMMdd"))
strdateFormat = CStr(Format(Today().AddDays(1), "yyyyMMdd"))
0
Comment
Question by:ohemaa
3 Comments
 
LVL 10

Accepted Solution

by:
Marcjev earned 200 total points
ID: 22780338
can someone explain what each of these does?

strdateFormat = CStr(Format(Today().Date, "yyyyMMdd"))
results in 20081022  (show todays date in the format specied)

 strdateFormat = CStr(Format(Today().AddDays(0), "yyyyMMdd"))
results in 20081022 (adds zero days, to date stays the same)

strdateFormat = CStr(Format(Today().AddDays(1), "yyyyMMdd"))
results in 20081023 (adds one to the date, so result is tomorrow...)

(assuming you posted vb.net code..., is surely not SQL code)
0
 
LVL 18

Assisted Solution

by:UnifiedIS
UnifiedIS earned 150 total points
ID: 22780366
These appear to be the same.
It changes today's date to a string formatted as 4-digit year, 2-digit month and 2-digit day and assigns that value to strdateFormat
strdateFormat = CStr(Format(Today().Date, "yyyyMMdd"))
strdateFormat = CStr(Format(Today().AddDays(0), "yyyyMMdd"))


This would return tomorrow's date in the same format
strdateFormat = CStr(Format(Today().AddDays(1), "yyyyMMdd"))
0
 
LVL 12

Assisted Solution

by:techExtreme
techExtreme earned 150 total points
ID: 22780417
Sure,
Basically what we are dealing with here is custom date formatting.
What you are doing is actually printing today's date  (represented by Today().Date in the sentence) using custom format (represented by string between the quotes).  
For the first line,
strdateFormat = CStr(Format(Today().Date, "yyyyMMdd"))
the format is "yyyyMMdd" wherein
yyyy refers to year and it will print year till 4 digits i.e. for year 2008, it will output 2008 as it is,
MM represents month in numbers from 01-12, for eg. it will be 02 for february,
dd represents day of month in number i.e. 02 for 2nd of march etc..
so yyyyMMdd will be 20081023 for 23rd october 2008

Second statement
 strdateFormat = CStr(Format(Today().AddDays(0), "yyyyMMdd"))

Here you are adding 0 days to the current date which will be the same as today's date hence the same result as above.

Third statement
strdateFormat = CStr(Format(Today().AddDays(1), "yyyyMMdd"))

Here you are adding one day so it will be  24th october 2008 and your format string yyyyMMdd
will print 20081024

Enjoy coding...
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now