Search Results

Search found 112 results on 5 pages for 'strftime'.

Page 1/5 | 1 2 3 4 5  | Next Page >

  • setlocale/strftime issue

    - by Manos Dilaverakis
    I am using the following to output the full name of a month in Greek. setlocale(LC_TIME, 'el_GR'); strftime("%B"); This works, except the output string is ISO-8859-7 (greek code page), which is a problem since I need a UTF-8 string. I could put this through iconv to convert it, but I was wondering if there was a way to do that without resorting to an extra function. Could you somehow tell strftime to output a UTF-8 string in this case?

    Read the article

  • Using a Unicode format for Python's `time.strftime()`

    - by Hosam Aly
    I am trying to call Python's time.strftime() function using a Unicode format string: u'%d\u200f/%m\u200f/%Y %H:%M:%S' (\u200f is the "Right-To-Left Mark" (RLM).) However, I am getting an exception that the RLM character cannot be encoded into ascii: UnicodeEncodeError: 'ascii' codec can't encode character u'\u200f' in position 2: ordinal not in range(128) I have tried searching for an alternative but could not find a reasonable one. Is there an alternative to this function, or a way to make it work with Unicode characters?

    Read the article

  • Is strftime (hour) showing wrong time?

    - by ander163
    I'm using this line to get the beginning time of the first day of the month. t = Time.now.to_date.beginning_of_month.beginning_of_day When i display this using t.strftime("%A %b %e @ %l:%m %p") it shows: Monday Feb 1 @ 12:02 AM The hour is always 12 (instead of 00), and more wierd the minute changes to match the month in integers. For the February date, it shows 12:02 AM I use .prior_month and .next_month on the variable to move forward or backwards in time. So when I move to June, this would display as Tuesday June 1 @ 12:06 AM But when I just show the value of "t" using a straight t.to_s, I get this time of 00:00:00, which is what I expect: Mon Feb 01 00:00:00 -0700 2010 A similar error occurs using end_of_day, but the hour is always 11 PM and the minute is the same integer value that matches the month in integers, i.e the time is 11:06 PM in June, 11:02 PM in February. Qurky? Admittedly a noob to Rails. Thanks for any comments or explanations.

    Read the article

  • Need to get 3 record for database on current date using sqlite

    - by Umaid
    SELECT rowid, Day, Advice from MainCategory where ((Day = ((cast(strftime('%d',date('now','-1 day')) as Integer)))) and (Month = (strftime('%m',date('now'))))) and ((Day = ((cast(strftime('%d',date('now')) as Integer)))) and (Month = (strftime('%m',date('now'))))) , ((Day = ((cast(strftime('%d',date('now','+1 day')) as Integer)))) and (Month = (strftime('%m',date('now',+1 month))))); What if i make my Month column in Integer data type then it would be. SELECT rowid, Month, Day, Advice from MainCategory where ((Day = ((cast(strftime('%d',date('now','-1 day')) as Integer)))) and (Month = (strftime('%m',date('now'))))) and ((Day = ((cast(strftime('%d',date('now')) as Integer)))) and (Month = (strftime('%m',date('now'))))) , ((Day = ((cast(strftime('%d',date('now','+1 day')) as Integer)))) and (Month = (strftime('%m',date('now',+1 month))))); Please note that I have over this scenerio when I am in middle of month but below query returns 2 records and 1 from begining from all 11 months as (feb is exclusive) then record will be 33 but i need three 3 records from the table and increment it on next button. Please write 3 querys one which return all three record on current date, next all 3 records must be incremented by 1 on every next button click finally all 3 records must be decremented by 1 on every previous button click keep last day and begining date on the month in minds else i have also achieved for middle of month. Running query but returns 33 records instead of 3. SELECT rowid,Month, Day, Advice from MainCategory where Day in ((cast(strftime('%d',date('now','-1 day')) as Integer)),(cast(strftime('%d',date('now')) as Integer)),(cast(strftime('%d',date('now','+1 day')) as Integer)));

    Read the article

  • C# Finisar SQLite DateTime Comparison Problem

    - by Emanuel
    My "task" database table look like this: [title] [content] [start_date] [end_date] [...] [...] [01.06.2010 20:10:36] [06.06.2010 20:10:36] [...] [...] [05.06.2010 20:10:36] [06.06.2010 20:10:36] And I want to find only those records that meet the condition that a given day is between start_date and end_date. I've tried the following SQL expression: SELECT * FROM task WHERE strftime ('%d', start_date) <= @day AND @day <= strftime ('%d', end_date) Where @day is an SQLiteParameter (eq 5). But no result is returned. How can I solve this problem? Thanks.

    Read the article

  • C# Finisar SQLite Date Format Problem

    - by Emanuel
    My "task" database table look like this: [title] [content] [start_date] [end_date] [...] [...] [01.06.2010 20:10:36] [06.06.2010 20:10:36] [...] [...] [05.06.2010 20:10:36] [06.06.2010 20:10:36] And I want to find only those records that meet the condition that a given day is between start_date and end_date. I've tried the following SQL expression: SELECT * FROM task WHERE strftime ('%d', 'start_date') <= @day AND @day <= strftime ('%d', 'end_date') Where @day is an SQLiteParameter (eq 5). But no result is returned. How can I solve this problem? Thanks.

    Read the article

  • SQL Query: How to determine "Seen during N hour" if given two DateTime time stamps?

    - by efess
    Hello all. I'm writing a statistics application based off a SQLite database. There is a table which records when users Login and Logout (SessionStart, SessionEnd DateTimes). What i'm looking for is a query that can show what hours user have been logged in, in sort of a line graph way- so between the hours of 12:00 and 1:00AM there were 60 users logged in (at any point), between the hours of 1:00 and 2:00AM there were 54 users logged in, etc... And I want to be able to run a SUM of this, which is why I can't bring the records into .NET and iterate through them that way. I've come up with a rather primative approach, a subquery for each hour of the day, however this approach has proved to be slow and slow. I need to be able to calculate this for a couple hundred thousand records in a split second.. SELECT case when (strftime('%s',datetime(date(sessionstart), '+0 hours')) > strftime('%s',sessionstart) AND strftime('%s',datetime(date(sessionstart), '+0 hours')) < strftime('%s',sessionend)) OR (strftime('%s',datetime(date(sessionstart), '+1 hours')) > strftime('%s',sessionstart) AND strftime('%s',datetime(date(sessionstart), '+1 hours')) < strftime('%s',sessionend)) OR (strftime('%s',datetime(date(sessionstart), '+0 hours')) < strftime('%s',sessionstart) AND strftime('%s',datetime(date(sessionstart), '+1 hours')) > strftime('%s',sessionend)) then 1 else 0 end as hour_zero, ... hour_one, ... hour_two, ........ hour_twentythree FROM UserSession I'm wondering what better way to determine if two DateTimes have been seen durring a particular hour (best case scenario, how many times it has crossed an hour if it was logged in multiple days, but not necessary)? The only other idea I had is have a "hour" table specific to this, and just tally up the hours the user has been seen at runtime, but I feel like this is more of a hack than the previous SQL. Any help would be greatly appreciated!

    Read the article

  • Why is my index view not working when I implement datepicker in my rails app

    - by user3736107
    Hi I am new to rails and would really appreciate some help, I am using the jQuery datepicker, the show view works however the index view doesn't, i get "undefined method `start_date' for nil:NilClass" in my index.html.erb file. Can you please let me know what is wrong with my index view and how i can fix it. The following are included in my app: meetups_controller.rb def show @meetup = Meetup.find(params[:id]) end def index @meetups = Meetup.where('user_id = ?', current_user.id).order('created_at DESC') end show.html.erb <h3>Title: <%= @meetup.title %></h3> <p>Start date: <%= @meetup.start_date.strftime("%B %e, %Y") %></p> <p>Start time: <%= @meetup.start_time.strftime("%l:%M %P") %></p> <p>End date: <%= @meetup.end_date.strftime("%B %e, %Y") %></p> <p>End time: <%= @meetup.end_time.strftime("%l:%M %P") %></p> index.html.erb <% if @meetups.any? %> <% @meetups.each do |meetup| %> <h3><%= link_to meetup.title, meetup_path(meetup) %></h3> <p>Start date: <%= meetup.start_date.strftime("%B %e, %Y") %></p> <p>Start time: <%= meetup.start_time.strftime("%l:%M %P") %></p> <p>End date: <%= @meetup.end_date.strftime("%B %e, %Y") %></p> <p>End time: <%= @meetup.end_time.strftime("%l:%M %P") %></p>

    Read the article

  • How to iterate in this query?

    - by Umaid
    for (int I=-1; I<30; I++) { for (int J=0; J<30; J++) { for(int K=1; K<30; K++) { SELECT rowid,Month, Day, Advice from MainCategory where Month= 'May ' and Day in ((cast(strftime('%d',date('now','+(I) day')) as Integer)),(cast(strftime('%d',date('now','+(J) day')) as Integer)),(cast(strftime('%d',date('now','+(K) day')) as Integer))); } } } And for the same reason how to decrement in this query for (int I=-1; I<30; I--) { for (int J=0; J<30; J--) { for(int K=1; K<30; K--) { SELECT rowid,Month, Day, Advice from MainCategory where Month= 'May ' and Day in ((cast(strftime('%d',date('now','(I) day')) as Integer)),(cast(strftime('%d',date('now','(J) day')) as Integer)),(cast(strftime('%d',date('now','(K) day')) as Integer))); } } }

    Read the article

  • Need little assistance

    - by Umaid
    I am iterating in current days, so need little assistance for (int I=-1; I<30; I++) { for (int J=0; J=30; J++) { for (int K=1; K=30; K++) { SELECT rowid,Month, Day, Advice from MainCategory where Month= 'May ' and Day in ((cast(strftime('%d',date('now','I day')) as Integer)),(cast(strftime('%d',date('now','J day')) as Integer)),(cast(strftime('%d',date('now','K day')) as Integer))); } } } What if i want to go in reverse order also for (int I=-1; I<30; I--) { for (int J=0; J=30; J--) { for (int K=1; K=30; K--) { SELECT rowid,Month, Day, Advice from MainCategory where Month= 'May ' and Day in ((cast(strftime('%d',date('now','I day')) as Integer)),(cast(strftime('%d',date('now','J day')) as Integer)),(cast(strftime('%d',date('now','K day')) as Integer))); } } } On every previous click, i want to fetch 3 records so do i need to iterate till 3 or make it on all record 30 in a month from which i want to fetch.

    Read the article

  • Generate a list of file names based on month and year arithmetic

    - by MacUsers
    How can I list the numbers 01 to 12 (one for each of the 12 months) in such a way so that the current month always comes last where the oldest one is first. In other words, if the number is grater than the current month, it's from the previous year. e.g. 02 is Feb, 2011 (the current month right now), 03 is March, 2010 and 09 is Sep, 2010 but 01 is Jan, 2011. In this case, I'd like to have [09, 03, 01, 02]. This is what I'm doing to determine the year: for inFile in os.listdir('.'): if inFile.isdigit(): month = months[int(inFile)] if int(inFile) <= int(strftime("%m")): year = strftime("%Y") else: year = int(strftime("%Y"))-1 mnYear = month + ", " + str(year) I don't have a clue what to do next. What should I do here? Update: I think, I better upload the entire script for better understanding. #!/usr/bin/env python import os, sys from time import strftime from calendar import month_abbr vGroup = {} vo = "group_lhcb" SI00_fig = float(2.478) months = tuple(month_abbr) print "\n%-12s\t%10s\t%8s\t%10s" % ('VOs','CPU-time','CPU-time','kSI2K-hrs') print "%-12s\t%10s\t%8s\t%10s" % ('','(in Sec)','(in Hrs)','(*2.478)') print "=" * 58 for inFile in os.listdir('.'): if inFile.isdigit(): readFile = open(inFile, 'r') lines = readFile.readlines() readFile.close() month = months[int(inFile)] if int(inFile) <= int(strftime("%m")): year = strftime("%Y") else: year = int(strftime("%Y"))-1 mnYear = month + ", " + str(year) for line in lines[2:]: if line.find(vo)==0: g, i = line.split() s = vGroup.get(g, 0) vGroup[g] = s + int(i) sumHrs = ((vGroup[g]/60)/60) sumSi2k = sumHrs*SI00_fig print "%-12s\t%10s\t%8s\t%10.2f" % (mnYear,vGroup[g],sumHrs,sumSi2k) del vGroup[g] When I run the script, I get this: [root@serv07 usage]# ./test.py VOs CPU-time CPU-time kSI2K-hrs (in Sec) (in Hrs) (*2.478) ================================================== Jan, 2011 211201372 58667 145376.83 Dec, 2010 5064337 1406 3484.07 Feb, 2011 17506049 4862 12048.04 Sep, 2010 210874275 58576 145151.33 As I said in the original post, I like the result to be in this order instead: Sep, 2010 210874275 58576 145151.33 Dec, 2010 5064337 1406 3484.07 Jan, 2011 211201372 58667 145376.83 Feb, 2011 17506049 4862 12048.04 The files in the source directory reads like this: [root@serv07 usage]# ls -l total 3632 -rw-r--r-- 1 root root 1144972 Feb 9 19:23 01 -rw-r--r-- 1 root root 556630 Feb 13 09:11 02 -rw-r--r-- 1 root root 443782 Feb 11 17:23 02.bak -rw-r--r-- 1 root root 1144556 Feb 14 09:30 09 -rw-r--r-- 1 root root 370822 Feb 9 19:24 12 Did I give a better picture now? Sorry for not being very clear in the first place. Cheers!! Update @Mark Ransom This is the result from Mark's suggestion: [root@serv07 usage]# ./test.py VOs CPU-time CPU-time kSI2K-hrs (in Sec) (in Hrs) (*2.478) ========================================================== Dec, 2010 5064337 1406 3484.07 Sep, 2010 210874275 58576 145151.33 Feb, 2011 17506049 4862 12048.04 Jan, 2011 211201372 58667 145376.83 As I said before, I'm looking for the result to b printed in this order: Sep, 2010 - Dec, 2010 - Jan, 2011 - Feb, 2011 Cheers!!

    Read the article

  • Rendering another Action without changing URL?

    - by Michael Stum
    I have this code in my Rails 3 controller: def index now = Time.now.utc.strftime("%m%d") redirect_to :action => "show", :id => now end def show begin @date = Time.parse("12#{params[:id]}") dbdate = params[:id] rescue ArgumentError @date = Time.now.utc dbdate = @date.strftime("%m%d") end @date = @date.strftime("%B %d") @events = Event.events_for_date(dbdate) end So basically index is just a specialized version of show, hence I want it to execute show, render the show.html.erb view - but I do not want to change the URL like redirect_to does. I have tried this approach: def index now = Time.now.utc.strftime("%m%d") params[:id] = now show render :action => "show" end Now, this works, but it just smells badly. I'm new to Ruby and Rails, so I just wonder if there is something fundamentally wrong or if there is a better way to do this?

    Read the article

  • Python: combining making two scripts into one

    - by Alex
    I have two separately made python scripts one that makes a sine wave sound based off time, and another that produces a sine wave graph that is based off the same time factors. I need help combining them into one running file. Here's the first: from struct import pack from math import sin, pi import time def au_file(name, freq, freq1, dur, vol): fout = open(name, 'wb') # header needs size, encoding=2, sampling_rate=8000, channel=1 fout.write('.snd' + pack('>5L', 24, 8*dur, 2, 8000, 1)) factor = 2 * pi * freq/8000 factor1 = 2 * pi * freq1/8000 # write data for seg in range(8 * dur): # sine wave calculations sin_seg = sin(seg * factor) + sin(seg * factor1) fout.write(pack('b', vol * 64 * sin_seg)) fout.close() t = time.strftime("%S", time.localtime()) ti = time.strftime("%M", time.localtime()) tis = float(t) tis = tis * 100 tim = float(ti) tim = tim * 100 if __name__ == '__main__': au_file(name='timeSound.au', freq=tim, freq1=tis, dur=1000, vol=1.0) import os os.startfile('timeSound.au') and the second is this: from Tkinter import * import math import time t = time.strftime("%S", time.localtime()) ti = time.strftime("%M", time.localtime()) tis = float(t) tis = tis / 100 tim = float(ti) tim = tim / 100 root = Tk() root.title("This very moment") width = 400 height = 300 center = height//2 x_increment = 1 # width stretch x_factor1 = tis x_factor2 = tim # height stretch y_amplitude = 50 c = Canvas(width=width, height=height, bg='black') c.pack() str1 = "sin(x)=white" c.create_text(10, 20, anchor=SW, text=str1) center_line = c.create_line(0, center, width, center, fill='red') # create the coordinate list for the sin() curve, have to be integers xy1 = [] xy2 = [] for x in range(400): # x coordinates xy1.append(x * x_increment) xy2.append(x * x_increment) # y coordinates xy1.append(int(math.sin(x * x_factor1) * y_amplitude) + center) xy2.append(int(math.sin(x * x_factor2) * y_amplitude) + center) sinS_line = c.create_line(xy1, fill='white') sinM_line = c.create_line(xy2, fill='yellow') root.mainloop()

    Read the article

  • How does my php function for converting a date to facebook timestamp look? New to PHP.

    - by First2Drown
    any suggestions to make it better? function convertToFBTimestamp($date){ $this_date = date('Y-m-d-H-i-s', strtotime($date)); $cur_date = date('Y-m-d-H-i-s'); list ($this_year, $this_month, $this_day, $this_hour, $this_min, $this_sec) = explode('-',$this_date); list ($cur_year, $cur_month, $cur_day, $cur_hour, $cur_min, $cur_sec) = explode('-',$cur_date); $this_unix_time = mktime($this_hour, $this_min, $this_sec, $this_month, $this_day, $this_year); $cur_unix_time = mktime($cur_hour, $cur_min, $cur_sec, $cur_month, $cur_day, $cur_year); $cur_unix_date = mktime(0, 0, 0, $cur_month, $cur_day, $cur_year); $dif_in_sec = $cur_unix_time - $this_unix_time; $dif_in_min = (int)($dif_in_sec / 60); $dif_in_hours = (int)($dif_in_min / 60); if(date('Y-m-d',strtotime($date))== date('Y-m-d')) { if($dif_in_sec < 60) { return $dif_in_sec." seconds ago"; } elseif($dif_in_sec < 120) { return "about a minute ago"; } elseif($dif_in_min < 60) { return $dif_in_min." minutes ago"; } else { if($dif_in_hours == 1) { return $dif_in_hours." hour ago"; } else { return $dif_in_hours." hours ago"; } } } elseif($cur_unix_date - $this_unix_time < 86400 ) { return strftime("Yesterday at %l:%M%P",$this_unix_time); } elseif($cur_unix_date - $this_unix_time < 259200) { return strftime("%A at %l:%M%P",$this_unix_time); } else { if($this_year == $cur_year) { return strftime("%B, %e at %l:%M%P",$this_unix_time); } else { return strftime("%B, %e %Y at %l:%M%P",$this_unix_time); } } }

    Read the article

  • rearranging a list of months

    - by MacUsers
    How can I list the numbers 01 to 12 (one for each of the 12 months) in such a way so that the current month always comes last where the oldest one is first. In other words, if the number is grater than the current month, it's from the previous year. e.g. 02 is Feb, 2011 (the current month right now), 03 is March, 2010 and 09 is Sep, 2010 but 01 is Jan, 2011. In this case, I'd like to have [09, 03, 01, 02]. This is what I'm doing to determine the year: for inFile in os.listdir('.'): if inFile.isdigit(): month = months[int(inFile)] if int(inFile) <= int(strftime("%m")): year = strftime("%Y") else: year = int(strftime("%Y"))-1 mnYear = month + ", " + str(year) I don't have a clue what to do next. What should I do here?

    Read the article

  • Facing trouble in retrieving relevant records

    - by Umaid
    SELECT * from MainCategory where Month = 'May' and Day in ((cast(strftime('%d',date('now','-1 day')) as Integer)),(cast(strftime('%d',date('now')) as Integer)),(cast(strftime('%d',date('now','+1 day')) as Integer))); Whenever I run this query in sqlite so it returns me 33 records instead of 3. I am insterested in fetching on 3 records of the current month but unable to do so, so plz assist. --Please note: if you can't assist so plz don't post irrelevant answer. I have also modified and try to make it simple but not achieve Select day, month from MainCategory where Month = 'May' and day in ((date('now','-1 day')),(date('now')),(date('now','+1 day')))

    Read the article

  • any rss feed lib for gae..

    - by zjm1126
    i want enable rss for gae on my site . and did you know the simple way to do this ? thanks this is a example i searched: class FeedHandler(BaseRequestHandler): def get(self,tags=None): blogs = Weblog.all().filter('entrytype =','post').order('-date').fetch(10) last_updated = datetime.datetime.now() if blogs and blogs[0]: last_updated = blogs[0].date last_updated = last_updated.strftime("%Y-%m-%dT%H:%M:%SZ") for blog in blogs: blog.formatted_date = blog.date.strftime("%Y-%m-%dT%H:%M:%SZ") self.response.headers['Content-Type'] = 'application/atom+xml' self.generate('atom.xml',{'blogs':blogs,'last_updated':last_updated}) any more simple ?

    Read the article

  • How to round down a DateTime value

    - by timpone
    I have a Location that can have Events. I want to have an upcoming_events method but want it to round down such that if someone looks at 10pm at night, it will show todays events. I have this: def upcoming_events d=Time.new d.strftime("%m-%d-%Y") l=Event.where('location_id=? and start_datetime>?',self.id, d) end I gets converted down correctly but in d.strftime but the query is: SELECT `events`.* FROM `events` WHERE (location_id=301 and start_datetime>'2012-06-20 02:49:23') Any idea how to just get it to do '2012-06-20'?

    Read the article

  • Compare two times without regard to Date associated - Ruby

    - by H55nick
    I am trying to find the difference in time (without days/years/months) of two different days. Example: #ruby >1.9 time1 = Time.now - 1.day time2 = Time.now #code to make changes #test: time1 == time2 # TRUE My solution: time1 = time1.strftime("%h:%m").to_time time2 = time2.strftime("%h:%m").to_time #test time1 == time2 #True #passes I was wondering if there was a better way of doing this? Maybe we could keep the Date the same as time1/time2?

    Read the article

  • SQL - Count grouped entries and then get the max values grouped by date

    - by Marcus
    hello, I am out of any logic how to write the right sql statment. I've got a sqlite table holding every played track in a row with played date/time Now I will count the plays of all artists, grouped by day and then find the artist with the max playcount per day. I used this Query SELECT COUNT(ARTISTID) AS artistcount, ARTIST AS artistname,strftime('%Y-%m-%d', playtime) AS day_played FROM playcount GROUP BY artistname to get this result "93"|"The Skygreen Leopards"|"2010-06-16" "2" |"Arcade Fire" |"2010-06-15" "2" |"Dead Kennedys" |"2010-06-15" "2" |"Wolf People" |"2010-06-15" "3" |"16 Horsepower" |"2010-06-15" "3" |"Alela Diane" |"2010-06-15" "46"|"Motorama" |"2010-06-15" "1" |"Ariel Pink's Haunted" |"2010-06-14" I tried then to query this virtual table but I always get false results in artistname. SELECT MAX(artistcount), artistname , day_played FROM ( SELECT COUNT(ARTISTID) AS artistcount, ARTIST AS artistname,strftime('%Y-%m-%d', playtime) AS day_played FROM playcount GROUP BY artistname ) GROUP BY strftime('%Y-%m-%d',day_played) result in this "93"|"lilium" |"2010-06-16" "46"|"Wolf People"|"2010-06-15" "30"|"of Montreal"|"2010-06-14" but the artist name is false. I think through the grouping by day, it just use the last artist, or so. I tested stuff like INNER JOIN or GROUP BY ... HAVING in trial and error, I read examples of similar issues but always get lost in columnnames and stuff (I am a bit burned out) I hope someone can give me a hint. thanks m

    Read the article

  • python calendar to calculate month backwards

    - by Suhail
    Hi, we are trying to create a calendar function in python. we have created a small content management system, the requirement is, there will be a drop down list on the top right hand corner of the website, which will give the options - Months - 1 month, 2 months, 3 months and so on..., if the user selects 8 months then it should show the postscount for the last 8 months. the issue is we tried to write a small code which would do the month calculations, but the bug is that it does not consider the months beyond the current year, it shows the postscount only for months of the current year. for example: if the user selects 3 months, it will show the count for the l 3 months i.e present month and the previous 2 months, but if the user selects option more than 4 months, it does not consider the months from previous year, it still shows the month of the present year only. I am pasting the code below:- def __getSpecifiedMailCount__(request, value): dbconnector= DBConnector() CdateList= "select cdate from mail_records" DateNow= datetime.datetime.today() DateNow= DateNow.strftime("%Y-%m") DateYear= datetime.datetime.today() DateYear= DateYear.strftime("%Y") DateMonth= datetime.datetime.today() DateMonth= DateMonth.strftime("%m") #print DateMonth def getMonth(value): valueDic= {"01": "Jan", "02": "Feb", "03": "Mar", "04": "Apr", "05": "May", "06": "Jun", "07": "Jul", "08": "Aug", "09": "Sep", "10": "Oct", "11": "Nov", "12": "Dec"} return valueDic[value] def getMonthYearandCount(yearmonth): MailCount= "select count(*) as mailcount from mail_records where cdate like '%s%s'" % (yearmonth, "%") MailCountResult= MailCount[0]['mailcount'] return MailCountResult MailCountList= [] MCOUNT= getMonthYearandCount(DateNow) MONTH= getMonth(DateMonth) MailCountDict= {} MailCountDict['monthyear']= MONTH + ' ' + DateYear MailCountDict['mailcount']= MCOUNT var_monthyear= MONTH + ' ' + DateYear var_mailcount= MCOUNT MailCountList.append(MailCountDict) i=1 k= int(value) hereMONTH= int(DateMonth) while (i < k): hereMONTH= int(hereMONTH) - 1 if (hereMONTH < 10): hereMONTH = '0' + str(hereMONTH) if (hereMONTH == '00') or (hereMONTH == '0-1'): break else: PMONTH= getMonth(hereMONTH) hereDateNow= DateYear + '-' + PMONTH hereDateNowNum= DateYear + '-' + hereMONTH PMCOUNT= getMonthYearandCount(hereDateNowNum) MailCountDict= {} MailCountDict['monthyear']= PMONTH + ' ' + DateYear MailCountDict['mailcount']= PMCOUNT var_monthyear= PMONTH + ' ' + DateYear var_mailcount= PMCOUNT MailCountList.append(MailCountDict) i = i + 1 #print MailCountList MailCountDict= {'monthmailcount': MailCountList} reportdata = MailCountDict['monthmailcount'] #print reportdata return render_to_response('test.html', locals())

    Read the article

  • How to display locale sensitive time format without seconds in python

    - by Tim Kersten
    I can output a locale sensitive time format using strftime('%X'), but this always includes seconds. How might I display this time format without seconds? >>> import locale >>> import datetime >>> locale.setlocale(locale.LC_ALL, 'en_IE.utf-8') 'en_IE.utf-8' >>> print datetime.datetime.now().strftime('%X') 12:22:43 >>> locale.setlocale(locale.LC_ALL, 'zh_TW.utf-8') 'zh_TW.utf-8' >>> print datetime.datetime.now().strftime('%X') 12?22?58? The only way I can think of doing this is attempting to parse the output of locale.nl_langinfo(locale.T_FMT) and strip out the seconds bit, but that brings it's own trickery. >>> print locale.nl_langinfo(locale.T_FMT) %H?%M?%S? >>> locale.setlocale(locale.LC_ALL, 'en_IE.utf-8') 'en_IE.utf-8' >>> print locale.nl_langinfo(locale.T_FMT) %T

    Read the article

  • Get seconds since epoch in any POSIX compliant shell

    - by mattbh
    I'd like to know if there's a way to get the number of seconds since the UNIX epoch in any POSIX compliant shell, without resorting to non-POSIX languages like perl, or using non-POSIX extensions like GNU awk's strftime function. Here are some solutions I've already ruled out... date +%s // Doesn't work on Solaris I've seen some shell scripts suggested before, which parse the output of date then derive seconds from the formatted gregorian calendar date, but they don't seem to take details like leap seconds into account. GNU awk has the strftime function, but this isn't available in standard awk. I could write a small C program which calls the time function, but the binary would be specific to a particular architecture. Is there a cross platform way to do this using only POSIX compliant tools? I'm tempted to give up and accept a dependency on perl, which is at least widely deployed. perl -e 'print time' // Cheating (non-POSIX), but should work on most platforms

    Read the article

  • Using python to play two sine tones at once

    - by Alex
    I'm using python to play a sine tone. The tone is based off the computer's internal time in minutes, but I'd like to simultaneously play one based off the second for a harmonized or dualing sound. This is what I have so far; can someone point me in the right direction? from struct import pack from math import sin, pi import time def au_file(name, freq, dur, vol): fout = open(name, 'wb') # header needs size, encoding=2, sampling_rate=8000, channel=1 fout.write('.snd' + pack('>5L', 24, 8*dur, 2, 8000, 1)) factor = 2 * pi * freq/8000 # write data for seg in range(8 * dur): # sine wave calculations sin_seg = sin(seg * factor) fout.write(pack('b', vol * 127 * sin_seg)) fout.close() t = time.strftime("%S", time.localtime()) ti = time.strftime("%M", time.localtime()) tis = float(t) tis = tis * 100 tim = float(ti) tim = tim * 100 if __name__ == '__main__': au_file(name='timeSound1.au', freq = tim, dur=1000, vol=1.0) import os os.startfile('timeSound1.au')

    Read the article

1 2 3 4 5  | Next Page >