Go Back   DeveloperBarn Forums > Programming & Scripting > ASP Development

Sponsored Links

Discuss "file name" in the ASP Development forum.

ASP Development - Learn coding practices and tips to get the best out of your Active Server Pages (ASP). The Classic ASP forum is for ASP/VBScript and ASP/JScript applications.


Reply « Previous Thread | Next Thread »
 
LinkBack Thread Tools Display Modes
  #1  
Old July 21st, 2008, 06:00 AM
guddu's Avatar
Barn Frequenter

 
Join Date: Jul 2008
Location: Oxford UK
Posts: 124
Thanks: 6
Thanked 3 Times in 2 Posts
Rep Power: 1
guddu is on a distinguished road
Default file name

hi
i want to create a file name in below format.any idea how to do this/

• The file name will be of the form:
• Company Code (1A) – derived from the unit company code
• “W” + week number (2N, 01-53) – counting from first week in January
• “D” + day of week number (1N, 1-7) – counting from Monday
• Year number (2N)
• “.txt”
E.g. “RW01D0108.txt” is the file from Monday 31st December 2007 (1st Jan was a Tuesday)

sorry for cross post.
__________________
Love is physical attraction and mental destruction
Reply With Quote
Sponsored Links
  #2  
Old July 21st, 2008, 06:30 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Try this:-
Code:
Dim filename, company_code, week_no, day_no, year_no, date_today
 
date_today = "31/12/2007"
 
company_code = "R"
week_no = datediff("ww","01/01/2008",date_today,vbMonday,vbFirstJan1)  + 1
if week_no<10 then week_no = "0" & week_no
day_no = "0" & weekday(date_today,vbMonday)
year_no = right(year(date_today),2)
filename = company_code & "W" & week_no & "D" & day_no & year_no & ".txt"
Hope that helps.
Reply With Quote
  #3  
Old July 21st, 2008, 06:43 AM
guddu's Avatar
Barn Frequenter

 
Join Date: Jul 2008
Location: Oxford UK
Posts: 124
Thanks: 6
Thanked 3 Times in 2 Posts
Rep Power: 1
guddu is on a distinguished road
Default

RR Thanks for reply.can u explain me what this codes are doing.why u are taken this date "01/01/2008".
Reply With Quote
  #4  
Old July 21st, 2008, 06:52 AM
guddu's Avatar
Barn Frequenter

 
Join Date: Jul 2008
Location: Oxford UK
Posts: 124
Thanks: 6
Thanked 3 Times in 2 Posts
Rep Power: 1
guddu is on a distinguished road
Default

we should use DatePart or DateDiff for this stuff.
Reply With Quote
  #5  
Old July 21st, 2008, 06:56 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

I have added notes to each line of the code.

Code:
'declare variables
Dim filename, company_code, week_no, day_no, year_no, date_today
 
'set date to today or whatever date you want manually or from a form element
date_today = "21/07/2008"
 
'set company code manually or from a form element
company_code = "R"
'calculate datediff in weeks (ww) between date at beginning of the year and date set above, based on Monday being first day of week. Then add 1 to the value as it starts at 0 not 1.
week_no = datediff("ww","01/01/2008",date_today,vbMonday,vbFirstJan1)  + 1
'if the number of weeks is less than 10 then add a zero to the front
if week_no<10 then week_no = "0" & week_no
'find the day of the week from the date set above, based on first day of the week being Monday
day_no = "0" & weekday(date_today,vbMonday)
'take the last 2 digits of the year from the date above
year_no = right(year(date_today),2)
'concatenate everything together into a filename variable.
filename = company_code & "W" & week_no & "D" & day_no & year_no & ".txt"
The 01/01/2008 is set to the first date of the year. You could set this dynamically using something like "01/01/" & year(date_today)

Hope that makes more sense.

Comments on this post
guddu agrees:
Reply With Quote
  #6  
Old July 21st, 2008, 07:04 AM
guddu's Avatar
Barn Frequenter

 
Join Date: Jul 2008
Location: Oxford UK
Posts: 124
Thanks: 6
Thanked 3 Times in 2 Posts
Rep Power: 1
guddu is on a distinguished road
Default

ok still i have doubt over this line.why u are adding 1 here
'calculate datediff in weeks (ww) between date at beginning of the year and date set above, based on Monday being first day of week. Then add 1 to the value as it starts at 0 not 1.
week_no = datediff("ww","01/01/2008",date_today,vbMonday,vbFirstJan1) + 1
Reply With Quote
  #7  
Old July 21st, 2008, 07:12 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Sorry, my brain's not quite working right today...

If you had a date in the first week of the year, using datediif would return 0, so I added 1 to it, ie it would be in week 1.

You are right, you could just use datepart.
Code:
week_no = datepart("ww",date_today,vbMonday,vbFirstJan1)
Hope that helps.
Reply With Quote
  #8  
Old July 21st, 2008, 07:18 AM
guddu's Avatar
Barn Frequenter

 
Join Date: Jul 2008
Location: Oxford UK
Posts: 124
Thanks: 6
Thanked 3 Times in 2 Posts
Rep Power: 1
guddu is on a distinguished road
Default

ok let me try as per my need.Thanks a lot RR.
Reply With Quote
  #9  
Old July 21st, 2008, 09:18 AM
guddu's Avatar
Barn Frequenter

 
Join Date: Jul 2008
Location: Oxford UK
Posts: 124
Thanks: 6
Thanked 3 Times in 2 Posts
Rep Power: 1
guddu is on a distinguished road
Default

hi
E.g. “RW01D0108.txt” is the file from Monday 31st December 2007 (1st Jan was a Tuesday)

see in example .
if we put date 31/12/2007 then in this case file name would be “RW01D0108.txt”
.but RR when i m using your code it returns me this file name RW53D0107.txt.
Reply With Quote
  #10  
Old July 21st, 2008, 09:52 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

I think, technically, it is correct in that the 31st would fall in to week 53 of 2007, although week 53 would only contain 1 day.

I think you could add some sort of filter for week 53 instances like:-
Code:
.
.
.
week_no = datepart("ww",date_today,vbMonday,vbFirstJan1)
'if the number of weeks is less than 10 then add a zero to the front
 
'find the day of the week from the date set above, based on first day of the week being Monday
day_no = "0" & weekday(date_today,vbMonday)
'take the last 2 digits of the year from the date above
year_no = year(date_today)
 
if week_no = 53 then
week_no = 1
year_no = year_no+1
end if
if week_no<10 then week_no = "0" & week_no
year_no = right(year_no,2)
filename = company_code & "W" & week_no & "D" & day_no & year_no & ".txt"
See if that helps.

<edit>I just tried this and I think you can get an instance of a week 54, on 31/12/2012. In the code above, that would make the previous week, 24-30 Dec week 1 of the following year, which would be wrong. I can't quite understand how you want to handle these events.</edit>

Last edited by richyrich; July 21st, 2008 at 10:01 AM.
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > ASP Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -4. The time now is 12:43 PM.



Content Relevant URLs by vBSEO 3.2.0