Solved

getting a date in mm/dd from DTOC

Posted on 2010-11-12
11
1,176 Views
Last Modified: 2012-05-10
lcEndLastWeek = DTOC(ldEndLastWeek)

results are 10/31/2010

I want it to be 10/31

waht is the best way for that?

Thanks
0
Comment
Question by:jaymz69
[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
  • 5
  • 4
  • 2
11 Comments
 
LVL 42

Accepted Solution

by:
pcelba earned 250 total points
ID: 34125045
The best way is:

LEFT(DTOC(ldEndLastWeek), 5)
0
 
LVL 14

Expert Comment

by:tusharkanvinde
ID: 34126078
I prefer using month and day functions as DTOC depends on the date setting.

textmerge('<<month(ldEndLastWeek)>>/<<day(ldEndLastWeek)>>')
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 34126483
I also go for using Month and Day since you might also have less for days and months less than 10.

? TRANSFORM(MONTH(dDate),'@L 99') + "/" + TRANSFORM(DAY(dDate),'@L 99')

@L Gives you 2 digits with leading zeroes.

In the example above you have 10/31/2010. What is it was 9/31/2010. You would get "9/31/".
0
Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

 
LVL 42

Expert Comment

by:pcelba
ID: 34126918
Captain, have you ever seen DTOC() function returning 9/31/2010 ?  :-)))

0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 34127437
I was just giving an example. So I changed 10 to 9 :-).

How about LEFT("1/1/2010",5) = "1/1/2".
0
 
LVL 14

Assisted Solution

by:tusharkanvinde
tusharkanvinde earned 250 total points
ID: 34127460
I like

STUFF(SUBSTR(DTOS(ldEndLastWeek),5),3,0,'/')
0
 
LVL 42

Expert Comment

by:pcelba
ID: 34128008
LEFT("1/1/2010",5) = "1/1/2"  is not this case because we have Date as the original parameter.

I suppose jayzm69 just needs to strip the year from the date which is already in required format (the year is at the end). The significant fact is the date format is OK for jayzm69 and he does not require any conversion:

AA/BB/YYYY

Thus LEFT(DTOC({^2010/9/1}), 5) will always return desired string because DTOC() adds leading zeros.

The STUFF() used by tusharkanvinde is cool.
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 34128219
There is a setting in regional part of Control Panel that causes the date to return without leading zeroes. That's why I try to avoid any loose ends.
0
 
LVL 42

Expert Comment

by:pcelba
ID: 34128512
Yes, you are right but this works when SET DATE is LONG or SHORT only. Or am I missing something?

OTOH, I also don't like functions or conversions which could provide ambiguous results.
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 34128577
That's why I proposed the DAY and MONTH functions. DTOS is stable across all as well.
0
 
LVL 42

Expert Comment

by:pcelba
ID: 34128647
So, let propose the post ID:34127460 as the solution and all others as assisted contributions...


BTW, I am just studying PARAMETERS (and LPARAMETERS) behavior. The interesting thing I've found is the possibility to RELEASE the variable used as a formal parameter (yes, this is not obvious deal with parameters).

This action unhides the variable originally used as the actual parameter (passed by ref) which is a little bit inconsistent with releasing the standard private variable where the originally hidden variable still remains hidden...

And yes, I know, this really don't look like a useful investigation. :-)
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Article by: Justin
In light of the WannaCry ransomware attack that affected millions of Windows machines, you might wonder if your Mac needs protecting. Yes, it does and here is how to do it.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

729 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