?
Solved

some date formats

Posted on 2008-10-22
3
Medium Priority
?
307 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 800 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 600 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 600 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

800 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