Solved

some date formats

Posted on 2008-10-22
3
290 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

708 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

15 Experts available now in Live!

Get 1:1 Help Now