Solved

some date formats

Posted on 2008-10-22
3
297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

732 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