Solved

some date formats

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

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
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.

695 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